Click here to Skip to main content
       

C#

 
GeneralRe: Basic Polymorphism Problem PinmemberBobJanova5-Oct-12 3:04 
QuestionC# linq group by Pinmemberrachel_m4-Oct-12 17:43 
AnswerRe: C# linq group by PinmvpOriginalGriff4-Oct-12 23:19 
GeneralRe: C# linq group by Pinmemberrachel_m5-Oct-12 2:48 
GeneralRe: C# linq group by PinmvpOriginalGriff5-Oct-12 3:29 
QuestionCrystal Reports : Database Login Prompt Issue PinmemberQuam Chang4-Oct-12 16:36 
AnswerRe: Crystal Reports : Database Login Prompt Issue PinmemberAmbiguousName4-Oct-12 20:00 
QuestionAggregate data into 5 min interval PinmemberMember 94707244-Oct-12 11:59 
Hello everyone,
 
I'm pretty new to this forum and have a question regarding to using C# to aggregate a csv file containing the vehicle position data into certain time interval. The format of the data is like follows:
 
Timestamp(s),    linkNo,   ......... NOx, PM10, CO2,
27000,           10,    .....         0.4,  1.2,  2.0
27000,           12,    .....         0.3,  1.4   3.0
27010,           10,    .....         0.4,  1.2,  2.0
27010,           12,    .....         0.3,  1.4   3.0
27020,           10,    .....         0.4,  1.2,  2.0
27020,           12,    .....         0.3,  1.4   3.0
.......
</pre>
 
The problem i'm trying to solve is to aggregate these data into 5 minutes interval and sum up all the pollutants (i.e. NOX, PM1O and CO2) on each link, the final results i want to get is:
<pre lang="xml">
TimeSlot,    linkNo,   ......... SumNOx, SumPM10, SumCO2,
27000,           10,    .....         1.2,  3.6,  6.0
27000,           12,    .....         0.3,  4.2   9.0
27300,           10,    .....         xx,  xx,  xx
27600,           12,    .....         xx,  xx,   xx
.......
<pre lang="c#"><
 
i have written some code to get the sum of these pollutants based on links, but i don't know how to aggregate them into each 5 minutes slot. here is the code i written so far:
 
    public partial class FormMain : Form
    {
        private double TimeSlotFunction(double SimulationTime)
        {
            double Time = 0;
            for (int i = 1; i <= 24; i++)
            {
                double StartTime = 27000 + 300 * (i - 1);
                double EndTime = StartTime + 300 * i;
                if (StartTime < SimulationTime && SimulationTime <= EndTime)
                {
 
                    Time = StartTime;
                    break;
                }
 
            }
            return Time;
        }
 
        private class LinkData
        {
            public string LinkName;
            public List<double> SimTime = new List<double>();
            public List<double> timeSlot = new List<double>();
            public List<double> NOx = new List<double>();
            public List<double> PM10 = new List<double>();
            public List<double> TotalCarbon = new List<double>();
            public double SumNOx;
            public double SumPM10;
            public double SumTotalCarbon;
            public double SumCO2;
        }
 
            foreach (string[] row in parsedData)
            {
                Entries.Add(row);
            }
/********Compute NOX, PM10, TotalCarbon for each link***********/
 
            var LinkDict = new Dictionary<string, LinkData>();
            for (int index = 1; index < Entries.Count; index++)
            {
                var row = Entries[index];
                if (!LinkDict.ContainsKey(row[1]))
                {
                    var newLink = new LinkData { LinkName = row[1] };
                    LinkDict.Add(row[1], newLink);
                }
 
                LinkDict[row[1]].SimTime.Add(Convert.ToDouble((row[0])));
                LinkDict[row[1]].NOx.Add(Convert.ToDouble((row[19])));
                LinkDict[row[1]].PM10.Add(Convert.ToDouble((row[20])));
                LinkDict[row[1]].TotalCarbon.Add(Convert.ToSingle((row[21])));
            }
 
            foreach (var linkValue in LinkDict.Values)
                linkValue.SumNOx = linkValue.NOx.Sum();
            foreach (var linkValue in LinkDict.Values)
                linkValue.SumPM10 = linkValue.PM10.Sum();
            foreach (var linkValue in LinkDict.Values)
                linkValue.SumTotalCarbon = linkValue.TotalCarbon.Sum();
            foreach (var linkValue in LinkDict.Values)
 
            using (var sw = new StreamWriter(@"D:\Work\C#\my project\my project\AlteredData.csv"))
            {
 
                foreach (var linkValue in LinkDict.Values)
                {
                    var sb = new StringBuilder();
                    //sb.Append(TimeSlotFunction(linkValue.SimTime.ToString());
                    //sb.Append(",");
                    sb.Append(linkValue.LinkName);
                    sb.Append(",");
                    sb.Append(linkValue.SumNOx.ToString());
                    sb.Append(",");
                    sb.Append(linkValue.SumPM10.ToString());
                    sb.Append(",");
                    sb.Append(linkValue.SumTotalCarbon.ToString());
                    sb.Append(",");
                    sb.Append(linkValue.SumCO2.ToString());
                    sb.Append(",");
                    sw.WriteLine(sb.ToString());
                }
 
            }
        }
 
 
I will be grateful if anyone can give me some advice.
 
cheers,
Simon
QuestionC# linq Pinmemberrachel_m4-Oct-12 9:36 
AnswerRe: C# linq PinmemberCollin Jasnoch4-Oct-12 10:00 
Question.exe Reference Problem - maybe Pinmemberdirsow4-Oct-12 7:52 
AnswerRe: .exe Reference Problem - maybe PinmemberEddy Vluggen4-Oct-12 9:01 
GeneralRe: .exe Reference Problem - maybe Pinmemberdirsow4-Oct-12 9:27 
GeneralRe: .exe Reference Problem - maybe PinmemberEddy Vluggen4-Oct-12 9:34 
GeneralRe: .exe Reference Problem - maybe Pinmemberdirsow4-Oct-12 9:41 
AnswerRe: .exe Reference Problem - maybe PinmemberBernhard Hiller4-Oct-12 21:00 
Questionhow to setting Four tier application in my application? Pinmembersomasundarapandian4-Oct-12 4:28 
AnswerRe: how to setting Four tier application in my application? PinmvpDave Kreskowiak4-Oct-12 6:45 
QuestionRe: how to setting Four tier application in my application? PinmemberEddy Vluggen4-Oct-12 9:02 
AnswerRe: how to setting Four tier application in my application? PinmvpOriginalGriff4-Oct-12 9:34 
Questionsqldatabaseconnectivity PinmemberMember 94545634-Oct-12 4:05 
AnswerRe: sqldatabaseconnectivity PinmemberRavi Bhavnani4-Oct-12 4:31 
AnswerRe: sqldatabaseconnectivity PinmvpRichard MacCutchan4-Oct-12 4:32 
AnswerRe: sqldatabaseconnectivity Pinmemberpalakshamb4-Oct-12 23:28 
QuestionCan an Attribute class find out, to which class it is actually attached? PinmemberAndy4114-Oct-12 2:42 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.


Advertise | Privacy | Mobile
Web01 | 2.8.140921.1 | Last Updated 22 Sep 2014
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid