123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104 |
- import datetime
- import os
- import urllib2
- import json
- settings_phaseId = 6
- if __name__ == '__main__':
-
- url = 'http://10.14.65.106:30087/event_rsu_rsu2cloud_spat_2024-4/_search'
-
- data = {
- "query": {
- "bool": {
- "must": [
-
-
-
-
-
-
-
- {
- "range": {
- "timestamp": {
- "gte": 1713861112000,
- "lte": 1713861273530
- }
- }
- }
- ]
- }
- },
- "size": 1000,
- "sort": [
- {
- "timestamp": {
- "order": "asc"
- }
- }
- ]
- }
-
- json_data = json.dumps(data)
-
- request = urllib2.Request(url, json_data)
- request.add_header('Content-Type', 'application/json; charset=UTF-8')
-
- response = urllib2.urlopen(request)
-
- response_data = response.read()
- print(response_data)
-
- json_response = json.loads(response_data)
- hits_array = list(json_response.get('hits').get('hits'))
- data_array = []
- for hits in hits_array:
- _source = hits.get('_source')
- intersections = list(_source.get('intersections'))
- for intersection in intersections:
- intersectionTimestamp = intersection.get('intersectionTimestamp')
- phases = list(intersection.get('phases'))
- for phase in phases:
- if phase.get('phaseId') == settings_phaseId:
- phaseStates = list(phase.get('phaseStates'))
- for phaseState in phaseStates:
- startTime = phaseState.get('startTime')
- if startTime == 0:
- data_array.append(
- {'intersectionTimestamp': intersectionTimestamp, 'light': phaseState.get('light')})
- currentIntersectionTimestamp = data_array[0].get('intersectionTimestamp')
- currentLight = data_array[0].get('light')
- result = []
-
- for e in data_array:
- intersectionTimestamp = e.get('intersectionTimestamp')
- light = e.get('light')
- if light == currentLight:
- continue
- if light != currentLight:
- if currentLight == 2 or currentLight == 3:
- result.append({'beginTime': currentIntersectionTimestamp, 'endTime': intersectionTimestamp, 'light': 1})
- else:
- result.append({'beginTime': currentIntersectionTimestamp, 'endTime': intersectionTimestamp, 'light': 0})
- currentIntersectionTimestamp = intersectionTimestamp
- currentLight = light
- if currentLight == 2 or currentLight == 3:
- result.append(
- {'beginTime': currentIntersectionTimestamp, 'endTime': currentIntersectionTimestamp + 10000, 'light': 1})
- else:
- result.append(
- {'beginTime': currentIntersectionTimestamp, 'endTime': currentIntersectionTimestamp + 10000, 'light': 0})
-
- print(data_array)
|