-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathaccount_report.py
68 lines (59 loc) · 1.91 KB
/
account_report.py
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
#!/usr/bin/env python3
"""Generates report for accounting data"""
import glob
import json
# Path to accounting data
PATH = '/cloud/cloud_configs/business_functions/accounting'
# You can set CLIENT to '' to grab all clients
CLIENT = 'otava'
# Adjust this to limit the date range to analyze
# EX: 202208 would only analyze things in the year 2022 with month of 08
# EX: 2022 would analyze all of 2022
DATERANGE = '202208'
fileList = glob.glob(f"{PATH}/{CLIENT}_accounting-{DATERANGE}*.json")
fileList.sort()
last_file = {
"name": "",
"ssd": 0,
"sata": 0
}
daily_changes = {
"ssd": [],
"sata": [],
"total": []
}
def average(lst):
"""Returns average of a list
Args:
lst (list): A list of numbers
Returns:
int: Returns average of numbers
"""
return sum(lst) / len(lst)
for file in fileList:
record = {
"name": file,
"ssd": 0,
"sata": 0
}
with open(file, 'r', encoding='utf_8') as file_read:
file_contents = file_read.read()
for content in file_contents.splitlines():
line = json.loads(content)
if line['disk'] == 'ssd':
record['ssd'] = record['ssd'] + line['size']
if line['disk'] == 'sata':
record['sata'] = record['sata'] + line['size']
if last_file['name'] != "":
SSD_CHANGE = record['ssd'] - last_file['ssd']
SATA_CHANGE = record['sata'] - last_file['sata']
TOTAL_CHANGE = SSD_CHANGE + SATA_CHANGE
daily_changes['ssd'].append(SSD_CHANGE)
daily_changes['sata'].append(SATA_CHANGE)
daily_changes['total'].append(TOTAL_CHANGE)
last_file = record
for day_change in daily_changes['total']:
print(f"Change rate is {day_change}")
print(f"Average daily change rate is : {average(daily_changes['total'])}")
print(f"Max daily change rate is {max(daily_changes['total'])}")
print(f"Minimum daily change rate is {min(daily_changes['total'])}")