I need a bit more info on your last question :) Perhaps create a new thread?
RabidDog5150 15 Newbie Poster
Might I suggest posting the Exception?
At initial glance I am incline to say that the path to the file is inaccessible by the remote machine as C:\blah will map to your local machine. Perhaps try putting it on a share? Again this is just an initial glance that might be nullified by your exception message
RabidDog5150 15 Newbie Poster
yeh problem is i think i need to put it into functions to load both of the csv files. other wise it dosnt work.
Fair enough, the problem is that creating a function is not just a matter of creating a function per say. A function facilitates a (oh the irony) function that the system has to perform. Now without knowing what the function needs to facilitate it is extremely diffiuclt to write a function. Perhaps you could tell us what the function needs to do as opposed to the code that needs to go in it? This will dictate the return types and the input parameters :) Considering your question as to the average values, you could create one function that parses a csv file and returns the required results and use that function multiple times as opposed to one function that does it all.
Example:
Given the previous algorythm you might declare a function like this
public static List<float> GetRowAverages(string dataSet){
var dataSet = dataSet.Split('\n');
var floatList = new List<float>();
foreach (var row in dataSet){
var split = row.Split(',');
var rowTotal = split.Sum(columnVal => float.Parse(columnVal));
floatList.Add(rowTotal / split.Length);
}
return floatList;
}
And then use it as follows
string fileData1 = System.IO.File.ReadAllText(@"C:\Users\40025634\Desktop\Project\SboxOutput.csv");
string fileData2 = System.IO.File.ReadAllText(@"C:\Users\40025634\Desktop\Project\AnotherOutput.csv");
var dataSetAverages1 = GetRowAverages(fileData1);
var dataSetAverages2 = GetRowAverages(fileData2);
var difList = dataSetAverages1.Select((t, i) => t - dataSetAverages2[i]).ToList();
Then you might wrap that in function called DoAllMyCVCalcs() etc etc
I hope you understand what I am getting at …
RabidDog5150 15 Newbie Poster
This seems very similiar to your other question which is about the algorythm to use. Might I suggest resolving the algorythm and then coming back to this?
RabidDog5150 15 Newbie Poster
I just reread your requirements and I fail to see how you can subtract the average of a row for the average of a column? the row average is based on the sum of the rows column values / the total number of columns. What the code above does is calculate the average for each row and then subtracts the averages of each row from the other dataset. I think that was the requirement? With a single value though it is going to be difficult to plot. What I think youmight be looking for is the one dataset value alongside the other dataset value but manipulate the code, hopefully you can derive a solution from it :)
RabidDog5150 15 Newbie Poster
Thanks will have to look through it a bit closer see what i can do with it but thank you for your post.
You shouldn't have to do too much to it, just replace the datasources initial, so row1 will become your first file read in (remove empty lines) and row 2 will become your second file read in (again remove empty lines)
RabidDog5150 15 Newbie Poster
Umm not sure this is what you looking for but had fun doing it
//Pseduo data
var row1 = "1,2,3,5,6" + Environment.NewLine + "5,5,6,7,8";
var row2 = "3,5,6,7,8" + Environment.NewLine + "3,2,5,3,1";
var dataSet1 = row1.Split('\n');
var dataSet2 = row2.Split('\n');
var floatList1 = new List<float>();
foreach (var row in dataSet1){
var split = row.Split(',');
var rowTotal = split.Sum(columnVal => float.Parse(columnVal));
floatList1.Add(rowTotal / split.Length);
}
var floatList2 = new List<float>();
foreach (var row in dataSet2) {
var split = row.Split(',');
var rowTotal = split.Sum(columnVal => float.Parse(columnVal));
floatList2.Add(rowTotal / split.Length);
}
var difList = floatList1.Select((t, i) => t - floatList2[i]).ToList();
foreach (var item in difList){
Console.WriteLine(item);
}
And then going really deep into queries
//Pseduo data
var row1 = "1,2,3,5,6" + Environment.NewLine + "5,5,6,7,8";
var row2 = "3,5,6,7,8" + Environment.NewLine + "3,2,5,3,1";
var dataSet1 = row1.Split('\n');
var dataSet2 = row2.Split('\n');
var floatList1 = (from row in dataSet1
select row.Split(',')
into split let rowTotal = split.Sum(columnVal => float.Parse(columnVal)) select rowTotal/split.Length).ToList();
var floatList2 = (from row in dataSet2
select row.Split(',')
into split let rowTotal = split.Sum(columnVal => float.Parse(columnVal)) select rowTotal/split.Length).ToList();
var difList = floatList1.Select((t, i) => t - floatList2[i]).ToList();
foreach (var item in difList) {
Console.WriteLine(item);
}
Pretty much achieves what your code does. Assumes a few things
1) All columns are float parseable
2) Row counts from both data sets are equal
Pretty certain it can be made more fault tolerant with a bit of work :)
RabidDog5150 15 Newbie Poster
there is a bit of a flaw in your model. First up you are going to have to create some sort of object model to properly achieve this.
Something like
class Cop{
private IList<License> _licenseList;
public IList<License> LicenseList {
// the ?? is a null check so if the _licenseList is null
// it will create a new instance of it for you. Short hand for
// an if statement checking if it is null.
get { return _licenseList ?? (_licenseList = new List<License>()); }
set { _licenseList = value; }
}
}
class License {
public LicenseType LicenseType { get; set; }
}
enum LicenseType {
Driver,
Pilot,
Diver
}
Then to achieve what you are doing you could do something like
var cop = new Cop();
//This will probably be populated from some data store.
cop.LicenseList.Add(new License{LicenseType = LicenseType.Driver});
//To query the licenses you can use lambda expressions
//List of all Drivers licenses
var driversLicenseList = cop.LicenseList.Where(x => x.LicenseType == LicenseType.Drivers);
//The first drivers license in the list
var firstDriversLicense = cop.LicenseList.FirstOrDefault(x=>x.LicenseType == LicenseType.Drivers);
This will give you the license. You can increase the declerations of the license class to include things like id numbers or the person the license belongs to, expiry date etc etc.
Hope it makes sense
RabidDog5150 15 Newbie Poster
Here is how to enumerate files in a directory and write their full names to the console. With a bit of modification you can add the full name of the file as the value so when selecting it you have the path to it. Rendering it to a picture box should just be a matter of supplying the url to the picture box.
DirectoryInfo dirInfo = new DirectoryInfo(@"C:\MyDirectory");
IEnumerable<FileInfo> fileList = dirInfo.EnumerateFiles();
foreach (FileInfo fileInfo in fileList){
Console.WriteLine(fileInfo.FullName);
}
RabidDog5150 15 Newbie Poster
Do you perhaps have some pseudo code? Are you talking about returning multiple values?
If you are talking about returning mulitple values then perhaps look at creating a class that contains the data properties you are going to need otherwise you could look at using a method which makes use of 'out' parameters.
Again, pseudo code would be extremly helpful in figuring out how to solve your problem