locked
C# how to calculate hourly average? RRS feed

  • Question

  • Hi guys,

    I am streaming data and i receive data on a real-time basis.  I am looking for a way to calculate the continuous flow of traffic.  So basically, I record an entry randomly during the hour and I do like to know if there is a way for me to calculate the average entry that I receive last hour?


    Please do not forget to click “Vote as Helpful” if the reply helps/directs you toward your solution and or "Mark as Answer" if it solves your question. This will help to contribute to the forum.

    Tuesday, June 10, 2014 4:32 AM

Answers

  • Hi CSharpNoob2011,

    I would suggest you store the traffic data into a database table, Access or Sql Server or something else. To calculate the average traffic using SQL statement would be very easy. ListBox is not so good I think.

    If you insist on using ListBox to store DataEntryStrings, then I think you need to find a way to extract the quantity in the strings during the last 60 minutes. Regular Expression will help you to do this.


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.


    • Edited by Caillen Wednesday, June 11, 2014 7:51 AM
    • Marked as answer by CSharpNoob2011 Wednesday, June 11, 2014 11:00 AM
    Wednesday, June 11, 2014 7:48 AM

All replies

  • Consider this naïve approach: define a queue of pairs “Time, DataSize”. Add new item when data arrive, but remove the head (old) items if the queue size exceeds a limit (1000 for example) or if the items are older than 1 hour. Then you can estimate the traffic by summing the sizes and dividing to interval.

    Tuesday, June 10, 2014 6:31 AM
  • The logic is like such let says you accumulate data entry in a listbox

    Now i need a way to make it work together.  

    string flow;
    
    listBox1.Items.Add(flow);
                while (listBox1.Items.Count >= 60)  //60 minutes
                    listBox1.Items.RemoveAt(0);        //remove the first item	

    The pair is Time (1 minute) and the data is a string that looks like this: 

    DataEntryString("{0}:\t{1}\t{2}\tLast:{3}\t{4:N0}/{5:N0}\t{6}x{7} #{8}", e.string1, e.string2....e.string8);      This DataEntryString is generated randomly (depending on the tracffic) every minute.

    The curly bracket {4} is quantity and I am trying to find the average per minute.

    I don't know if I make any sense.


    Please do not forget to click “Vote as Helpful” if the reply helps/directs you toward your solution and or "Mark as Answer" if it solves your question. This will help to contribute to the forum.

    Tuesday, June 10, 2014 10:57 AM
  • Hi CSharpNoob2011,

    I would suggest you store the traffic data into a database table, Access or Sql Server or something else. To calculate the average traffic using SQL statement would be very easy. ListBox is not so good I think.

    If you insist on using ListBox to store DataEntryStrings, then I think you need to find a way to extract the quantity in the strings during the last 60 minutes. Regular Expression will help you to do this.


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.


    • Edited by Caillen Wednesday, June 11, 2014 7:51 AM
    • Marked as answer by CSharpNoob2011 Wednesday, June 11, 2014 11:00 AM
    Wednesday, June 11, 2014 7:48 AM