
added another boundary condition : this is for when the data itself is incomplete, where its missing some one or two data
@6beb404c145a4e71a6755337ad8fa13329b0a543
--- action.py
+++ action.py
... | ... | @@ -164,6 +164,15 @@ |
164 | 164 |
@Action.route('/gps_update') |
165 | 165 |
class fileUpload(Resource): |
166 | 166 |
def post(self): |
167 |
+ token = request.headers.get('Authorization') |
|
168 |
+ if not token: |
|
169 |
+ return jsonify({'result': 'fail', 'msg': '토큰이 없습니다.'}) |
|
170 |
+ else: |
|
171 |
+ # Decode the token to verify it |
|
172 |
+ decoded_token = jwt.decode(token, "secret", algorithms=['HS256']) |
|
173 |
+ #print(decoded_token) |
|
174 |
+ user_id = decoded_token['id'] |
|
175 |
+ |
|
167 | 176 |
db = DB() |
168 | 177 |
data = request.get_json() |
169 | 178 |
if len(data["trip_id"]) !=64: |
... | ... | @@ -171,6 +180,17 @@ |
171 | 180 |
|
172 | 181 |
if len(data["trip_log"]["timestamp"]) == 0: |
173 | 182 |
return jsonify({500 :"ERROR! 'trip_log' is empty!"}) |
183 |
+ |
|
184 |
+ time_stamp_len = len(data["trip_log"]["timestamp"]) |
|
185 |
+ latitude_len = len(data["trip_log"]["latitude"]) |
|
186 |
+ longitude_len = len(data["trip_log"]["longitude"]) |
|
187 |
+ |
|
188 |
+ if time_stamp_len != latitude_len or latitude_len != longitude_len: |
|
189 |
+ return jsonify( |
|
190 |
+ { |
|
191 |
+ 500: f"ERROR! Mismatching length of data in trip_log! \n timestamp : {time_stamp_len} \n latitude : {latitude_len} \n longitude : {longitude_len}" |
|
192 |
+ } |
|
193 |
+ ) |
|
174 | 194 |
|
175 | 195 |
df = pd.DataFrame(data["trip_log"]) |
176 | 196 |
df["user_id"] = data["user_id"] |
... | ... | @@ -179,16 +199,6 @@ |
179 | 199 |
|
180 | 200 |
columns = df.columns |
181 | 201 |
data_csv_block = df.to_csv(header=False, index=False) |
182 |
- |
|
183 |
- token = request.headers.get('Authorization') |
|
184 |
- if not token: |
|
185 |
- return jsonify({'result': 'fail', 'msg': '토큰이 없습니다.'}) |
|
186 |
- |
|
187 |
- else: |
|
188 |
- # Decode the token to verify it |
|
189 |
- decoded_token = jwt.decode(token, "secret", algorithms=['HS256']) |
|
190 |
- #print(decoded_token) |
|
191 |
- user_id = decoded_token['id'] |
|
192 | 202 |
|
193 | 203 |
# GPS 데이터베이스에 삽입 |
194 | 204 |
db.insert_gps_data(data_csv_block, columns) |
--- unit_test_insert_gps_command.sh
+++ unit_test_insert_gps_command.sh
... | ... | @@ -41,3 +41,35 @@ |
41 | 41 |
} |
42 | 42 |
}' -H "Content-Type: application/json" -X POST http://192.168.0.195:15857/action/gps_update |
43 | 43 |
|
44 |
+ |
|
45 |
+curl -d '{ |
|
46 |
+ "user_id":"testaccount-mismatchlen-long", |
|
47 |
+ "trip_id":"9911c80c165b85c7cfbaedd89cb0e0d39bea6d7eb93cadab9b264abc350bb888", |
|
48 |
+ "trip_log": { |
|
49 |
+ "latitude":[37.778282, 37.778283, 37.778284, 37.778285, 37.778286, 37.778287, 37.778288, 37.778289, 37.778290, 37.778291, 37.778292, 37.778293, 37.778294, 37.778295, 37.778296], |
|
50 |
+ "longitude":[128.129373, 128.129374, 128.129375, 128.129376, 128.129377, 128.129378, 128.129379, 128.129380, 128.129381, 128.129382, 128.129383, 128.129384, 128.129385, 128.129386], |
|
51 |
+ "timestamp":["2024-07-11 16:23:19.667", "2024-07-11 16:24:19.667", "2024-07-11 16:25:19.667", "2024-07-11 16:26:19.667", "2024-07-11 16:27:19.667", "2024-07-11 16:28:19.667", "2024-07-11 16:29:19.667", "2024-07-11 16:30:19.667", "2024-07-11 16:31:19.667", "2024-07-11 16:32:19.667", "2024-07-11 16:33:19.667", "2024-07-11 16:34:19.667", "2024-07-11 16:35:19.667", "2024-07-11 16:36:19.667", "2024-07-11 16:37:19.667"] |
|
52 |
+ } |
|
53 |
+}' -H "Content-Type: application/json" -X POST http://192.168.0.195:15857/action/gps_update |
|
54 |
+ |
|
55 |
+curl -d '{ |
|
56 |
+ "user_id":"testaccount-mismatchlen-lat", |
|
57 |
+ "trip_id":"9911c80c165b85c7cfbaedd89cb0e0d39bea6d7eb93cadab9b264abc350bb888", |
|
58 |
+ "trip_log": { |
|
59 |
+ "latitude":[37.778282, 37.778283, 37.778284, 37.778285, 37.778286, 37.778287, 37.778288, 37.778289, 37.778290, 37.778291, 37.778292, 37.778293, 37.778294, 37.778295], |
|
60 |
+ "longitude":[128.129373, 128.129374, 128.129375, 128.129376, 128.129377, 128.129378, 128.129379, 128.129380, 128.129381, 128.129382, 128.129383, 128.129384, 128.129385, 128.129386, 128.129387], |
|
61 |
+ "timestamp":["2024-07-11 16:23:19.667", "2024-07-11 16:24:19.667", "2024-07-11 16:25:19.667", "2024-07-11 16:26:19.667", "2024-07-11 16:27:19.667", "2024-07-11 16:28:19.667", "2024-07-11 16:29:19.667", "2024-07-11 16:30:19.667", "2024-07-11 16:31:19.667", "2024-07-11 16:32:19.667", "2024-07-11 16:33:19.667", "2024-07-11 16:34:19.667", "2024-07-11 16:35:19.667", "2024-07-11 16:36:19.667", "2024-07-11 16:37:19.667"] |
|
62 |
+ } |
|
63 |
+}' -H "Content-Type: application/json" -X POST http://192.168.0.195:15857/action/gps_update |
|
64 |
+ |
|
65 |
+ |
|
66 |
+curl -d '{ |
|
67 |
+ "user_id":"testaccount-fifteen-timestamp", |
|
68 |
+ "trip_id":"9911c80c165b85c7cfbaedd89cb0e0d39bea6d7eb93cadab9b264abc350bb888", |
|
69 |
+ "trip_log": { |
|
70 |
+ "latitude":[37.778282, 37.778283, 37.778284, 37.778285, 37.778286, 37.778287, 37.778288, 37.778289, 37.778290, 37.778291, 37.778292, 37.778293, 37.778294, 37.778295, 37.778296], |
|
71 |
+ "longitude":[128.129373, 128.129374, 128.129375, 128.129376, 128.129377, 128.129378, 128.129379, 128.129380, 128.129381, 128.129382, 128.129383, 128.129384, 128.129385, 128.129386, 128.129387], |
|
72 |
+ "timestamp":["2024-07-11 16:23:19.667", "2024-07-11 16:24:19.667", "2024-07-11 16:25:19.667", "2024-07-11 16:26:19.667", "2024-07-11 16:27:19.667", "2024-07-11 16:28:19.667", "2024-07-11 16:29:19.667", "2024-07-11 16:30:19.667", "2024-07-11 16:32:19.667", "2024-07-11 16:33:19.667", "2024-07-11 16:34:19.667", "2024-07-11 16:35:19.667", "2024-07-11 16:36:19.667", "2024-07-11 16:37:19.667"] |
|
73 |
+ } |
|
74 |
+}' -H "Content-Type: application/json" -X POST http://192.168.0.195:15857/action/gps_update |
|
75 |
+ |
Add a comment
Delete comment
Once you delete this comment, you won't be able to recover it. Are you sure you want to delete this comment?