Skip to content

Commit 0965a68

Browse files
committed
CV3-85-story(event): add device downtime to report data
- add helper function for getting devices analytics - add helper function for calculating downtime and convert it to human readable date time - add query that retrieves the devices analytics including downtime of the devices [Delivers CV3-85]
1 parent 03c5c13 commit 0965a68

File tree

6 files changed

+241
-161
lines changed

6 files changed

+241
-161
lines changed

api/analytics/all_analytics_query.py

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
import graphene
22
from helpers.auth.admin_roles import admin_roles
33
from helpers.calendar.all_analytics_helper import (
4-
AllAnalyticsHelper, Event, BookingsCount
4+
AllAnalyticsHelper, Event, BookingsCount, DeviceAnalytics
55
)
66
from api.role.schema import Role
77
from helpers.calendar.analytics_helper import CommonAnalytics
88
from helpers.auth.authentication import Auth
99
from api.room.schema import Room
10+
from api.devices.schema import Devices
1011
from utilities.utility import percentage_formater
1112
from helpers.auth.user_details import get_user_from_db
1213
from utilities.validator import verify_location_id
@@ -37,6 +38,7 @@ class AllAnalytics(graphene.ObjectType):
3738
cancellations_percentage = graphene.Float()
3839
app_bookings_percentage = graphene.Float()
3940
bookings_count = graphene.List(BookingsCount)
41+
device_analytics = graphene.List(DeviceAnalytics)
4042

4143

4244
class Query(graphene.ObjectType):
@@ -69,6 +71,11 @@ def resolve_all_analytics(self, info, **kwargs):
6971
start_date, end_date = CommonAnalytics.all_analytics_date_validation(
7072
self, start_date, end_date
7173
)
74+
device_query = Devices.get_query(info)
75+
device_analytics = AllAnalyticsHelper.get_devices_analytics(
76+
self,
77+
device_query
78+
)
7279
query = Room.get_query(info)
7380
room_analytics, bookings, percentages_dict, bookings_count = \
7481
AllAnalyticsHelper.get_all_analytics(
@@ -98,6 +105,14 @@ def resolve_all_analytics(self, info, **kwargs):
98105
events=analytic['room_events'],
99106
)
100107
analytics.append(current_analytic)
108+
device_analytics_list = []
109+
for device_object in device_analytics:
110+
device_analytic = DeviceAnalytics(
111+
device_name=device_object['device_name'],
112+
device_id=device_object['device_id'],
113+
down_time=device_object['down_time']
114+
)
115+
device_analytics_list.append(device_analytic)
101116
return AllAnalytics(
102117
bookings=bookings,
103118
checkins_percentage=percentage_formater(
@@ -117,4 +132,5 @@ def resolve_all_analytics(self, info, **kwargs):
117132
bookings
118133
),
119134
bookings_count=bookings_count,
120-
analytics=analytics)
135+
analytics=analytics,
136+
device_analytics=device_analytics_list)
Lines changed: 78 additions & 106 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
all_analytics_query = '''
1+
all_analytics_query = """
22
query {
33
allAnalytics(startDate:"jul 11 2018", endDate:"jul 12 2018", locationId:1) { # noqa: E501
44
checkinsPercentage
@@ -25,10 +25,23 @@
2525
totalBookings
2626
period
2727
}
28+
deviceAnalytics{
29+
deviceName
30+
deviceId
31+
}
2832
}
2933
}
30-
'''
31-
all_analytics_query_invalid_locationid = '''
34+
"""
35+
all_analytics_query_down_time = """
36+
query {
37+
allAnalytics(startDate:"jul 11 2018", endDate:"jul 12 2018", locationId:1) { # noqa: E501
38+
deviceAnalytics{
39+
downTime
40+
}
41+
}
42+
}
43+
"""
44+
all_analytics_query_invalid_locationid = """
3245
query {
3346
allAnalytics(startDate:"jul 11 2018", endDate:"jul 12 2018", locationId:10) { # noqa: E501
3447
checkinsPercentage
@@ -57,84 +70,69 @@
5770
}
5871
}
5972
}
60-
'''
73+
"""
6174

6275
all_analytics_query_response = {
63-
"data": {
64-
"allAnalytics": {
65-
"checkinsPercentage": 0.0,
66-
"appBookingsPercentage": 0.0,
67-
"autoCancellationsPercentage": 0.0,
68-
"cancellationsPercentage": 0.0,
69-
"bookings": 1,
70-
"analytics": [
71-
{
72-
"roomName": "Entebbe",
73-
"cancellations": 0,
74-
"cancellationsPercentage": 0.0,
75-
"autoCancellations": 0,
76-
"numberOfBookings": 1,
77-
"checkins": 0,
78-
"checkinsPercentage": 0.0,
79-
"bookingsPercentageShare": 100.0,
80-
"appBookings": 0,
81-
"appBookingsPercentage": 0.0,
82-
"events": [
83-
{
84-
"durationInMinutes": 45
85-
}
86-
]
87-
},
88-
{
89-
"roomName": "Tana",
90-
"cancellations": 0,
91-
"cancellationsPercentage": 0.0,
92-
"autoCancellations": 0,
93-
"numberOfBookings": 0,
94-
"checkins": 0,
95-
"checkinsPercentage": 0.0,
96-
"bookingsPercentageShare": 0.0,
97-
"appBookings": 0,
98-
"appBookingsPercentage": 0.0,
99-
"events": [
100-
{
101-
"durationInMinutes": 0
102-
}
103-
]
104-
}
105-
],
106-
"bookingsCount": [
107-
{
108-
"totalBookings": 1,
109-
"period": "Jul 11 2018"
110-
},
111-
{
112-
'totalBookings': 0,
113-
'period': 'Jul 12 2018'
76+
"data": {
77+
"allAnalytics": {
78+
"checkinsPercentage": 0.0,
79+
"appBookingsPercentage": 0.0,
80+
"autoCancellationsPercentage": 0.0,
81+
"cancellationsPercentage": 0.0,
82+
"bookings": 1,
83+
"analytics": [
84+
{
85+
"roomName": "Entebbe",
86+
"cancellations": 0,
87+
"cancellationsPercentage": 0.0,
88+
"autoCancellations": 0,
89+
"numberOfBookings": 1,
90+
"checkins": 0,
91+
"checkinsPercentage": 0.0,
92+
"bookingsPercentageShare": 100.0,
93+
"appBookings": 0,
94+
"appBookingsPercentage": 0.0,
95+
"events": [{"durationInMinutes": 45}],
96+
},
97+
{
98+
"roomName": "Tana",
99+
"cancellations": 0,
100+
"cancellationsPercentage": 0.0,
101+
"autoCancellations": 0,
102+
"numberOfBookings": 0,
103+
"checkins": 0,
104+
"checkinsPercentage": 0.0,
105+
"bookingsPercentageShare": 0.0,
106+
"appBookings": 0,
107+
"appBookingsPercentage": 0.0,
108+
"events": [{"durationInMinutes": 0}],
109+
},
110+
],
111+
"bookingsCount": [
112+
{"totalBookings": 1, "period": "Jul 11 2018"},
113+
{"totalBookings": 0, "period": "Jul 12 2018"},
114+
],
115+
"deviceAnalytics": [
116+
{
117+
"deviceName": "Samsung",
118+
"deviceId": 1,
119+
# "downTime": "this device was seen {}".format(
120+
# downtime_value),
121+
}
122+
],
114123
}
115-
]
116124
}
117-
}
118125
}
119126

120127
all_analytics_query_response_super_admin_with_invalid_locationid = {
121128
"errors": [
122129
{
123130
"message": "Location Id does not exist",
124-
"locations": [
125-
{
126-
"line": 3,
127-
"column": 7
128-
}
129-
],
130-
"path": [
131-
"allAnalytics"
132-
]
131+
"locations": [{"line": 3, "column": 7}],
132+
"path": ["allAnalytics"],
133133
}
134134
],
135-
"data": {
136-
"allAnalytics": None
137-
}
135+
"data": {"allAnalytics": None},
138136
}
139137

140138
all_analytics_query_response_super_admin = {
@@ -157,11 +155,7 @@
157155
"bookingsPercentageShare": 50.0,
158156
"appBookings": 0,
159157
"appBookingsPercentage": 0.0,
160-
"events": [
161-
{
162-
"durationInMinutes": 890
163-
}
164-
]
158+
"events": [{"durationInMinutes": 890}],
165159
},
166160
{
167161
"roomName": "Krypton",
@@ -174,11 +168,7 @@
174168
"bookingsPercentageShare": 25.0,
175169
"appBookings": 0,
176170
"appBookingsPercentage": 0.0,
177-
"events": [
178-
{
179-
"durationInMinutes": 155
180-
}
181-
]
171+
"events": [{"durationInMinutes": 155}],
182172
},
183173
{
184174
"roomName": "Bujumbura",
@@ -191,11 +181,7 @@
191181
"bookingsPercentageShare": 25.0,
192182
"appBookings": 0,
193183
"appBookingsPercentage": 0.0,
194-
"events": [
195-
{
196-
"durationInMinutes": 92
197-
}
198-
]
184+
"events": [{"durationInMinutes": 92}],
199185
},
200186
{
201187
"roomName": "Kampala",
@@ -208,11 +194,7 @@
208194
"bookingsPercentageShare": 0.0,
209195
"appBookings": 0,
210196
"appBookingsPercentage": 0.0,
211-
"events": [
212-
{
213-
"durationInMinutes": 0
214-
}
215-
]
197+
"events": [{"durationInMinutes": 0}],
216198
},
217199
{
218200
"roomName": "Algiers",
@@ -225,28 +207,18 @@
225207
"bookingsPercentageShare": 0.0,
226208
"appBookings": 0,
227209
"appBookingsPercentage": 0.0,
228-
"events": [
229-
{
230-
"durationInMinutes": 0
231-
}
232-
]
233-
}
210+
"events": [{"durationInMinutes": 0}],
211+
},
234212
],
235213
"bookingsCount": [
236-
{
237-
"totalBookings": 7,
238-
"period": "Jul 11 2018"
239-
},
240-
{
241-
"totalBookings": 5,
242-
"period": "Jul 12 2018"
243-
}
244-
]
214+
{"totalBookings": 7, "period": "Jul 11 2018"},
215+
{"totalBookings": 5, "period": "Jul 12 2018"},
216+
],
245217
}
246218
}
247219
}
248220

249-
analytics_query_for_date_ranges = '''
221+
analytics_query_for_date_ranges = """
250222
query {
251223
allAnalytics(startDate:"jul 11 2020", endDate:"jul 12 2018") {
252224
checkinsPercentage
@@ -275,4 +247,4 @@
275247
}
276248
}
277249
}
278-
'''
250+
"""

fixtures/devices/devices_fixtures.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
"allDevices": [
1818
{
1919
"id": "1",
20-
"lastSeen": "2018-06-08T11:17:58.785136", # noqa: E501
20+
"lastSeen": "2019-04-10T13:28:45", # noqa: E501
2121
"dateAdded": "2018-06-08T11:17:58.785136", # noqa: E501
2222
"name": "Samsung",
2323
"location": "Kampala"
@@ -44,7 +44,7 @@
4444
{
4545
"dateAdded": "2018-06-08T11:17:58.785136",
4646
"id": "1",
47-
"lastSeen": "2018-06-08T11:17:58.785136",
47+
"lastSeen": "2019-04-10T13:28:45",
4848
"location": "Kampala",
4949
"name": "Samsung"
5050
}
@@ -68,7 +68,7 @@
6868
"data": {
6969
"specificDevice": {
7070
"id": "1",
71-
"lastSeen": "2018-06-08T11:17:58.785136", # noqa: E501
71+
"lastSeen": "2019-04-10T13:28:45", # noqa: E501
7272
"dateAdded": "2018-06-08T11:17:58.785136", # noqa: E501
7373
"name": "Samsung",
7474
"location": "Kampala"

0 commit comments

Comments
 (0)