-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathExample.java
173 lines (141 loc) · 5.14 KB
/
Example.java
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
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.Iterator;
// Utilized JSON simple because it is free
// and it would parse through the JSON file
// as that is the input
import org.json.simple.JSONArray;
import org.json.simple.JSONObject;
import org.json.simple.parser.JSONParser;
import org.json.simple.parser.ParseException;
public class Example {
private static final String filePath = "C:\\Users\\Nabeel\\Documents\\task.json";//change the file name to other parsers
private static final String INSTANCENAME = "instanceName";
private static final String NAME = "name";
private static final String INSTANCEID = "instanceId";
private static final String STATUS = "status";
private static final String START = "createDate";
private static final String END = "closeDate";
public static void main(String[] args) {
try {
// read the json file
FileReader reader = new FileReader(filePath);
JSONParser jsonParser = new JSONParser();
// it is an array so we read the array
JSONArray mainArray = (JSONArray) jsonParser.parse(reader);
//test case
Iterator iterate = mainArray.iterator();
// go through each big set
int closed= 0;
int open = 0;
//number of open and closed cases
while(iterate.hasNext()){
JSONObject arrayObject = (JSONObject) iterate.next();
// goes to each big element in JSON
// from that we read the input and spit out the answer
// case 1
//since arrayObject.get spits out an object instanceName
// we give it the date in the way I am assuming
// 2014-10-06T23:32:33Z
// read start and end to get the date
// read what is opened and what is closed on that date
String example = "2015-02-22";
//String[] parts = example.split("-");
String case1Start = (String) arrayObject.get(START);
// fetch start date
String case1End = (String) arrayObject.get(END);
//fetch end date
//check first if case1Start and case1End are not null
if(case1Start!=null && case1Start.contains(example) )
//the task started on the date
open++;
// it can start then
// * rewrite later to include next day case
else if(case1End != null && case1End.contains(example) )
closed++;
//System.out.println(case1Start);
//System.out.println(case1End);
//System.out.println(example);
}
System.out.println("number of open cases: " + open );
System.out.println("number of closed cases: " + closed);
System.out.println("total: " + (open + closed) );
//CASE 3
// go through each big set
// instanceId example
String example = "2015-02-22";
//number of tasks opened and closed in that range
while(iterate.hasNext()){
JSONObject arrayObject = (JSONObject) iterate.next();
//String[] parts = example.split("-");
//compare if it is in that open or close day
//then check if in that time frame
// hours then minutes then secs
// add if it passes the task
//
String = (String) arrayObject.get(START);
// fetch when started
// add the first open as the most recent because one didnt exist previously
// check if it is closer to the date
// day
// hour
// minute
// sec
// if passes all then replace temp with this one cause it's closer
//
if(case1Start!=null && case1Start.contains(example) )
//the task started on the date
open++;
// it can start then
// * rewrite later to include next day case
else if(case1End != null && case1End.contains(example) )
closed++;
//System.out.println(case1Start);
//System.out.println(case1End);
//System.out.println(example);
}
System.out.println("number of open cases: " + open );
System.out.println("number of closed cases: " + closed);
System.out.println("total: " + (open + closed) );
//CASE 4
// go through each big set
// instanceId example
String example = "680";
//number of tasks opened and closed in that range
while(iterate.hasNext()){
JSONObject arrayObject = (JSONObject) iterate.next();
//String[] parts = example.split("-");
//compare if it is in that open or close day
//then check if in that time frame
// hours then minutes then secs
// add if it passes the task
//
String instanceId = (String) arrayObject.get(INSTANCEID);
//check how many times this appears
//
if(case1Start!=null && case1Start.contains(example) )
//the task started on the date
open++;
// it can start then
// * rewrite later to include next day case
else if(case1End != null && case1End.contains(example) )
closed++;
//System.out.println(case1Start);
//System.out.println(case1End);
//System.out.println(example);
}
System.out.println("number of open cases: " + open );
System.out.println("number of closed cases: " + closed);
System.out.println("total: " + (open + closed) );
} catch (FileNotFoundException ex) {
ex.printStackTrace();
} catch (IOException ex) {
ex.printStackTrace();
} catch (ParseException ex) {
ex.printStackTrace();
} catch (NullPointerException ex) {
ex.printStackTrace();
}
}
}