forked from ombegov/dcoi
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathimportHistoricalData.py
130 lines (115 loc) · 3.2 KB
/
importHistoricalData.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
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
###
# This script may be used to import a full dump of the historical DCOI data to
# a local sqlite database.
###
import csv
import sys
import itertools
import sqlite3
import config
try:
filename = sys.argv[1]
except IndexError:
print ('No filename specified!')
exit()
print ('Filename: ', filename)
# Variables we will re-use
conn = sqlite3.connect(config.DB_CONFIG['file'])
c = conn.cursor()
rows = []
with open(filename, 'r') as datafile:
reader = csv.DictReader(datafile)
for row in reader:
quarter, year = row['quarter'].split(' ')
quarter = int(quarter[1])
year = int(year)
# We only want valid, recent records.
if row['recordValidity'] != 'Valid Facility' or year < 2017:
continue
print(row['dataCenterID'], year, quarter)
rows.append({
'id' : row['dataCenterID'],
'quarter' : quarter,
'year': year,
'agency' : row['agencyAbbrev'],
'component' : row['component'],
'ownershipType' : row['ownershipType'],
'sharedServicesPosition' : row['interAgencySharedServicesPosition'],
'tier' : row['dataCenterTier'],
'country' : row['country'],
'grossFloorArea' : row['grossFloorArea'],
'keyMissionFacility' : int(row['keyMissionFacility'].lower() == 'yes'),
'keyMissionFacilityType' : row['keyMissionFacility1'],
'electricityMetered' : int(row['tcoElectricityIsMetered'].lower() == 'yes'),
'avgElectricityUsage' : row['averageElectricityUsage'],
'avgITElectricityUsage' : row['averageITElectricityUsage'],
'underutilizedServers' : row['underutilizedServers'],
'downtimeHours' : row['facilityDowntimeActual'],
'plannedAvailabilityHours' : row['facilityAvailabilityPlanned'],
'mainframesCount' : row['totalMainframes'],
'HPCCount' : row['totalHPCClusterNodes'],
'serverCount' : row['totalServers'],
'virtualHostCount' : row['totalVirtualHosts'],
'closingStage' : row['closingStage'],
'closingTargetDate' : row['closingTargetDate'],
'comments' : row['comments']
})
c.executemany('''
INSERT INTO datacenters
(
id,
quarter,
year,
agency,
component,
ownershipType,
sharedServicesPosition,
tier,
country,
grossFloorArea,
keyMissionFacility,
keyMissionFacilityType,
electricityMetered,
avgElectricityUsage,
avgITElectricityUsage,
underutilizedServers,
downtimeHours,
plannedAvailabilityHours,
mainframesCount,
HPCCount,
serverCount,
virtualHostCount,
closingStage,
closingTargetDate,
comments
) VALUES (
:id,
:quarter,
:year,
:agency,
:component,
:ownershipType,
:sharedServicesPosition,
:tier,
:country,
:grossFloorArea,
:keyMissionFacility,
:keyMissionFacilityType,
:electricityMetered,
:avgElectricityUsage,
:avgITElectricityUsage,
:underutilizedServers,
:downtimeHours,
:plannedAvailabilityHours,
:mainframesCount,
:HPCCount,
:serverCount,
:virtualHostCount,
:closingStage,
:closingTargetDate,
:comments
)
''', rows)
conn.commit()
conn.close()
exit()