Click here to Skip to main content
15,894,223 members
Home / Discussions / C#
   

C#

 
AnswerRe: Assistence required with this spacific Program Pin
Richard MacCutchan4-Oct-12 23:04
mveRichard MacCutchan4-Oct-12 23:04 
AnswerRe: Assistence required with this spacific Program Pin
V.5-Oct-12 0:41
professionalV.5-Oct-12 0:41 
QuestionHow to configure post-build events for setup/deployment projects in Visual Studio Pin
Tridip Bhattacharjee4-Oct-12 21:25
professionalTridip Bhattacharjee4-Oct-12 21:25 
AnswerRe: How to configure post-build events for setup/deployment projects in Visual Studio Pin
Richard MacCutchan4-Oct-12 21:50
mveRichard MacCutchan4-Oct-12 21:50 
GeneralRe: How to configure post-build events for setup/deployment projects in Visual Studio Pin
Tridip Bhattacharjee6-Oct-12 7:07
professionalTridip Bhattacharjee6-Oct-12 7:07 
GeneralRe: How to configure post-build events for setup/deployment projects in Visual Studio Pin
Richard MacCutchan6-Oct-12 7:18
mveRichard MacCutchan6-Oct-12 7:18 
QuestionBasic Polymorphism Problem Pin
AmbiguousName4-Oct-12 18:54
AmbiguousName4-Oct-12 18:54 
AnswerRe: Basic Polymorphism Problem Pin
DaveyM694-Oct-12 20:29
professionalDaveyM694-Oct-12 20:29 
AnswerRe: Basic Polymorphism Problem Pin
AmbiguousName4-Oct-12 20:56
AmbiguousName4-Oct-12 20:56 
GeneralRe: Basic Polymorphism Problem Pin
DaveyM694-Oct-12 21:35
professionalDaveyM694-Oct-12 21:35 
AnswerRe: Basic Polymorphism Problem Pin
AmbiguousName4-Oct-12 21:45
AmbiguousName4-Oct-12 21:45 
GeneralRe: Basic Polymorphism Problem Pin
DaveyM694-Oct-12 22:18
professionalDaveyM694-Oct-12 22:18 
AnswerRe: Basic Polymorphism Problem Pin
BobJanova5-Oct-12 0:52
BobJanova5-Oct-12 0:52 
GeneralRe: Basic Polymorphism Problem Pin
DaveyM695-Oct-12 1:19
professionalDaveyM695-Oct-12 1:19 
GeneralRe: Basic Polymorphism Problem Pin
BobJanova5-Oct-12 3:04
BobJanova5-Oct-12 3:04 
QuestionC# linq group by Pin
rachel_m4-Oct-12 17:43
rachel_m4-Oct-12 17:43 
AnswerRe: C# linq group by Pin
OriginalGriff4-Oct-12 23:19
mveOriginalGriff4-Oct-12 23:19 
GeneralRe: C# linq group by Pin
rachel_m5-Oct-12 2:48
rachel_m5-Oct-12 2:48 
GeneralRe: C# linq group by Pin
OriginalGriff5-Oct-12 3:29
mveOriginalGriff5-Oct-12 3:29 
QuestionCrystal Reports : Database Login Prompt Issue Pin
Quam Chang4-Oct-12 16:36
Quam Chang4-Oct-12 16:36 
AnswerRe: Crystal Reports : Database Login Prompt Issue Pin
AmbiguousName4-Oct-12 20:00
AmbiguousName4-Oct-12 20:00 
QuestionAggregate data into 5 min interval Pin
bad_kid4-Oct-12 11:59
bad_kid4-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:

XML
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:

C#
    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 Pin
rachel_m4-Oct-12 9:36
rachel_m4-Oct-12 9:36 
Question.exe Reference Problem - maybe Pin
dirsow4-Oct-12 7:52
dirsow4-Oct-12 7:52 
AnswerRe: .exe Reference Problem - maybe Pin
Eddy Vluggen4-Oct-12 9:01
professionalEddy Vluggen4-Oct-12 9:01 

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

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