-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRawData.java
More file actions
179 lines (153 loc) · 4.27 KB
/
Copy pathRawData.java
File metadata and controls
179 lines (153 loc) · 4.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
import java.text.Format;
import java.text.SimpleDateFormat;
public class RawData {
private String localTime;
private String exchangeTime;
private String date;
private String sym;
private String price;
private String volume;
private String buyBroker;
private String sellBroker;
private int[] localTimeArray = new int[4];
private int[] exchangeTimeArray = new int[4];
private int[] delay = new int[4];
private String timeDelay;
public RawData(){
}
/*
* the input format will be like:
* "Sep 9, 2015 09:30:00.012004000 Eastern Summer Time"
*/
public void setLocalTime(String rawData){
String[] splited = rawData.split("\\s+");
this.localTime = splited[3].replace(".", ":").substring(0, splited[3].length()-3);
}
/*
* the input format will be like:
* "1441805400009007"
*/
public void setExchangeTime(String rawData){
long rawTime = Long.valueOf(rawData.replace("\"", ""));
long time = rawTime/1000000;
String modTime = String.format("%1$06d", rawTime%1000000);
java.util.Date hourMinuteSecond = new java.util.Date((long)time*1000);
Format formatter = new SimpleDateFormat("HH:mm:ss");
//strTime stores HH:mm:ss info
String strTime = formatter.format(hourMinuteSecond);
this.exchangeTime = strTime+ ":" + modTime;
}
/*
* the input format will be like:
* "Sep 9, 2015 09:30:00.012004000 Eastern Summer Time"
*/
public void setDate(String rawData){
String[] splited = rawData.replaceAll(",","").replace("\"", "").split("\\s+");
String month;
String day;
String year;
//get month from raw data
switch(splited[0]){
//here I just wrote September because it is the only month in the data
case "Jan":
month = "01";
break;
case "Sep":
month = "09";
break;
default:
month = "To be updated month";
break;
}
//get day and year from raw data
day = String.format("%1$02d", Integer.valueOf(splited[1]));
year = splited[2];
this.date = year + month + day;
}
/*
* the input format will be like:
* "FTP.DB.A "
*/
public void setSYM(String rawData){
//get rid of all spaces
this.sym = rawData.replace("\"", "").replaceAll("\\s+","");
}
/*
* the input format will be like:
* "54000000"
*/
public void setPrice(String rawData){
Long price = Long.valueOf(rawData.replace("\"", ""))/1000000;
String modPrice = String.format("%1$06d", Long.valueOf(rawData.replace("\"", ""))%1000000);
this.price = price.toString() + "." + modPrice;
}
/*
* the input format will be like:
* "5000"
*/
public void setVolume(String rawData){
this.volume = rawData.replace("\"", "");
}
/*
* the input format will be like:
* "7"
*/
public void setBuyBroker(String rawData){
this.buyBroker = rawData.replace("\"", "");
}
/*
* the input format will be like:
* "70"
*/
public void setSellBroker(String rawData){
this.sellBroker = rawData.replace("\"", "");
}
public String getLocalTime(){
return this.localTime;
}
public String getExchangeTime(){
return this.exchangeTime;
}
public String getDate(){
return this.date;
}
public String getSYM(){
return this.sym;
}
public String getPrice(){
return this.price;
}
public String getVolume(){
return this.volume;
}
public String getBuyBroker(){
return this.buyBroker;
}
public String getSellBroker(){
return this.sellBroker;
}
public int getDelay(){
String[] localTime = this.localTime.split(":");
String[] exchangeTime = this.exchangeTime.split(":");
//store the time into an int array
for(int i=0;i<4;i++){
localTimeArray[i] = Integer.valueOf(localTime[i]);
exchangeTimeArray[i] = Integer.valueOf(exchangeTime[i]);
}
int carry;
//since the time is always in a format of "09:30:00:******", I would make things simple here
//******Important,need to be updated when calculating complex time delay*********
for(int i=3;i>0;i--){
if (localTimeArray[i] >= exchangeTimeArray[i] ){
delay[i] = localTimeArray[i] - exchangeTimeArray[i];
carry = 0;
}
else{
carry = 1;
}
}
//System.out.println(String.format("%1$06d", delay[3]));
timeDelay = String.format("%1$06d", delay[3]);
return delay[3];
}
}