|
lordoftrades wrote: so I need pretty detailed information I think
So do we! How should we know how to help you, if you can't even describe what kind of data consolidation should be done.
Since it is comma separated you can start by reading the file line by line and splitting it into pieces using String.Split .
Then you'd parse the first column (date) with DateTime.Parse[^] ignore the second column (time)
and parse the rest of the columns using Double.Parse[^].
If it is the first line or the date hasn't changed yet do your data consolidation calculations.
If the date changed write out the last consolidated data and reinitialise the data consolidation with the values for the new date.
Rinse, lather, repeat!
Regards,
— Manfred
"I had the right to remain silent, but I didn't have the ability!"
Ron White, Comedian
|
|
|
|
|
Yes you are right. Sorry. I need to get the following data:
For each date I need value from the
first row third column (or [2])
higest value from the fourth column
lowest value from fifth column
finally value from the last row sixth column.
This should all be written to new file adding the date to first column [0], and thereafter the data in same order as above.
I see your point on this:
Quote: If the date changed write out the last consolidated data and reinitialise the data consolidation with the values for the new date.
Not sure though, how to write it out.
Kind regards
Espen
|
|
|
|
|
This is really straight forward stuff. Either you do this yourself or hire a coder.
lordoftrades wrote: Not sure though, how to write it out.
This is not very descriptive. What exactly are you having difficulties with?
Have you even tried anything yet?
Another thing is that I just can't see how this would take weeks to accomplish.
Regards,
— Manfred
"I had the right to remain silent, but I didn't have the ability!"
Ron White, Comedian
|
|
|
|
|
What you need to do does not seem that complex, but, as Manfred points out, to respond we need a complete specification.
Questions:
1. each day's data is transformed into a single line of cvs ?
2. 1/3/2012,09:30:00,409.3,410,409,409.79,657901, for example, maps to exactly what in the new file ?
3. statements like: for every fourth column-entry in the source cvs file, I need to: .... and return ... are helpful.
If you seek to aid everyone that suffers in the galaxy, you will only weaken yourself … and weaken them. It is the internal struggles, when fought and won on their own, that yield the strongest rewards… If you care for others, then dispense with pity and sacrifice and recognize the value in letting them fight their own battles." Darth Traya
|
|
|
|
|
In a response to my answer OP posted something that some people would consider a "requirement specification".
Here it is![^]
Cheers!
"I had the right to remain silent, but I didn't have the ability!"
Ron White, Comedian
|
|
|
|
|
Hi Manfred,
Yes, I read the OP's response to your query, and your response.
I agreed with your statement in your response to the OP: "This is not very descriptive."
And, that's why I asked the OP for a more "complete" specification
yours, Bill
If you seek to aid everyone that suffers in the galaxy, you will only weaken yourself … and weaken them. It is the internal struggles, when fought and won on their own, that yield the strongest rewards… If you care for others, then dispense with pity and sacrifice and recognize the value in letting them fight their own battles." Darth Traya
|
|
|
|
|
Hi
If I understand your question right:
1. Yes, i want the data to be: date,open,high,low,close
2. When the second column is 09:30:00 we know that this is the first row for this date. But sometimes there are no records the first minutes/hours, so it doesn't necessarily have to be true that 09:30:00 is the first row. It could be 10:15:00 in a stock with less trading activity. Anyhow, the first row as in your example:
Quote: 1/3/2012,09:30:00,409.3,410,409,409.79,657901
should return 409.3 as "Open" value.
3. The statements would be something like this:
startrow for date X
endrow for date X
Return:
1. date = X
2. Open= Column(3) value in startrow
3. High = search for higest value in range startrow to endrow, column(4)
4. Low = search for lowest value in range...... Column(5)
5. Close = Column (6) value in endrow
Kind regards
Espen
|
|
|
|
|
lordoftrades wrote: so there are many inputs for each date.
And that means ten thousand? One million? One billion?
|
|
|
|
|
Hi
Sorry for not being clear, I'm so used to live in this bubble of stockmarket data.
If it is 5 min data, there could be up to 130 inputs (or lines) for a single date in one textfile. And if there are 400 days with data we could end up with a total of 52.000 lines, if my math is correct..
And at the end this should be 400 lines with end of day data..

|
|
|
|
|
That is a trivial amount of data and any method that you come up with that doesn't have bugs will process it in a trivial amount of time.
|
|
|
|
|
Now that your specification is clear(er), I can suggest to you some architectural features of the C# code you might employ. I won't "flesh that out," since if I did I think I'd be writing commercial code for free, and that's not what CP is for. Also, I am confident that if you can code this in VBA, you can code it in C# !
Given your possible 400 lines of distilled analysis, I'd see no problem reading/parsing your data into a generic List<struct>. The struct and the List<struct> might look like this:
private struct DayTrade
{
public DateTime DateOpen;
public DateTime StartTime;
public double OpenPrice;
public double StartPrice;
public double HighPrice;
public double LowPrice;
public int SharesTraded;
}
private List<DayTrade> DayTradeList = new List<DayTrade>(); I would create the generic List, and then serialize/deserialize it to save/access the data. For serialization to XML, or binary, you could evaluate .NET's built-in facilities in System.Xml and System.Runtime.Serialization; or, you could look into using the MS DataContractSerializer Class, or you could check out Mehdi Gholam's excellent fastJSON and fastBinaryJSON libraries published here on CodeProject.
To get ready to parse the data into structs, I'd define these variables:
private char[] splitLineBreak = Environment.NewLine.ToCharArray();
private char[] splitComma = new char[] {','};
private string currentLine;
private List<string> lineList = new List<string>();
private List<string> splitLineList = new List<string>(); Steps in parsing would be:
1. split the data into lines:
lineList = data.Split(splitLineBreak, StringSplitOptions.RemoveEmptyEntries).ToList<string>(); 2. in the parsing loop:
for (int i = 0; i < lineList.Count; i++)
{
// create a new struct
DayTrade OneDaysTrade = new DayTrade();
// get the current line
currentLine = lineList[i];
// split the current line by comma
splitLineList = currentLine.Split(splitComma, StringSplitOptions.RemoveEmptyEntries).ToList<string>();
// somewhere in your parsing algorithm you are going to be using code like this:
// OneDaysTrade.DateOpen = Convert.ToDateTime(splitLineList[0]);
// OneDaysTrade.StartTime = Convert.ToDateTime(splitLineList[1]);
// OneDaysTrade.OpenPrice = Convert.ToDouble(splitLineList[2]);
//
// and so forth
// finally you are going to add the fleshed out struct to your List
DayTradeList.Add(OneDaysTrade);
} Of course your parsing code will have to handle the transition in reading the data from one day to the next, but I am sure you are already aware of how to do that, and how to create any intermediate variables required. And I'm sure you know how to compare each current day's high and low, and save the highest high, and lowest low, etc.
If you seek to aid everyone that suffers in the galaxy, you will only weaken yourself … and weaken them. It is the internal struggles, when fought and won on their own, that yield the strongest rewards… If you care for others, then dispense with pity and sacrifice and recognize the value in letting them fight their own battles." Darth Traya
|
|
|
|
|
Thanks a lot!! This is a great help!
Kind regards
Espen
|
|
|
|
|
Hi there, I am using VS2012 and .NET Framework 4.5
I am making a simple picture viewer. I have completed,
Creating a picture viewer, which has open, previous, and next buttons.
Now i was wondering how i can add in the Zoom feature into this.
What i exactly want is, according to mouse wheel movement the picture should zoom in or out corresponding to direction of rotation of the mouse wheel. Also the image should zoom in or out based on the point where the mouse pointer is currently present.
One more thing, the picture viewer is fullscreen at all time.
I hope somebody could reply soon... Thank you
|
|
|
|
|
|
Guessing for your text, you will need to built the zoom functionality yourself (Which is actually quite easy btw). Just catch the mouse scroll and recalculate the amount of pixels to show. Ie; Zoom in once; 1px becomes 4pxs etc..
|
|
|
|
|
|
CodeProject is your friend: [^], [^].
For an old (but still relevant, imho) caution against using the PictureBox to pan and zoom: [^].
If you seek to aid everyone that suffers in the galaxy, you will only weaken yourself … and weaken them. It is the internal struggles, when fought and won on their own, that yield the strongest rewards… If you care for others, then dispense with pity and sacrifice and recognize the value in letting them fight their own battles." Darth Traya
|
|
|
|
|
I'm stuck on a problem and would like your help. I have a class - “public class NmeaInterpreter” well known and written by Jon Person - , where it is sent and receive events through delegates / events:
/ / **********
public class NmeaInterpreter
public delegate void PositionReceivedEventHandler (string latitude, string longitude);
....
....
PositionReceivedEventHandler PositionReceived public event;
....
...
/ / ************
I have two more Forms( ) :
Form 2 ( ) - where I set the serial port, and sending the sentences received by GPS.
Form 1 ( ) - generally where I analyze and get the values and step formatted for a TextBox.
Although the Form1 ( ) deal with events :
/ / ****
NmeaInterpreter GPS NmeaInterpreter = new ( ) ;
public Form1 ( )
{
InitializeComponent ( ) ;
GPS.PositionReceived = new NmeaInterpreter.PositionReceivedEventHandler ( GPS_PositionReceived ) ;
}
private void GPS_PositionReceived (string latitude, string longitude )
{
TestBox.Text latitude.ToString = ();
}
/ / **************
- I cannot read or have no value in Textboxes ! Any idea?
When I debug step by step, just noticed that it ignores the methods created ...
Another thing is that if I have only one Form( ), where I treat the events and do the settings of the serial ports , it works ... but if I want to pass the data / strings from “class NmeaInterpreter” and show to another Form ( ) , does not work ! Where is the error?
Thanks for the support
Jose
|
|
|
|
|
You aren't wiring your event up with +=. So, your GPS.PositionReceived should have += after it, instead of =.
|
|
|
|
|
Greetings
Something happen with my code when I posted here. Here you are again (Form1()):
NmeaInterpreter GPS = new NmeaInterpreter();
public Form1()
{
InitializeComponent();
GPS.PositionReceived += new NmeaInterpreter.PositionReceivedEventHandler(GPS_PositionReceived);
}
private void GPS_PositionReceived(string latitude, string longitude)
{
TestBox.Text = latitude.ToString();
}
Anyway, I tested and nothing! I should receive on my TextBox the returned values. I tested the code with step info and I got the date from GPS, I receive the data in the class, but no output to my Form () TextBox.
Thank you for your reply.
Rgds
Jose
|
|
|
|
|
This would suggest that the PositionReceived event is not being fired.
|
|
|
|
|
Greetings,
Yes. But why? Whats wrong? The
public class NmeaInterpreter is a well known one, written by Jon Person, author of "GPS.NET" (www.gpsdotnet.com).
Rgds
Jose
|
|
|
|
|
How the heck would I know? Why not ask the author? He's the best placed person to answer questions about his code. He should be able to tell you why his code is not raising this event.
|
|
|
|
|
It has nothing to do with the author code. It's something I did wrong and now can not uncover. The author has done much sharing. Anyway, thank you for your reply.
Rgds
Jose
|
|
|
|
|
If you think about it, your code will be receiving this event because you have subscribed to it (tick, you have done that) and there is something in the component itself that is triggering the event. Now, this may be raised due to a combination of things that you need to set; the author is the best person to tell you under what circumstances this event is raised, and what else you need to do. As far as I can see in your code, there is absolutely nothing wrong with your syntax.
|
|
|
|
|