File size: 6,776 Bytes
2152c06 | 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 131 132 133 134 | '''
Hello! Thank you for downloading a CORGIS library. However, you do not
need to open this file. Instead you should make your own Python file and
add the following line:
import electricity
Then just place the files you downloaded alongside it.
'''
import os as _os
import pickle as _pickle
__all__ = ['get_utility']
def _tifa_definitions():
return {"type": "ModuleType",
"fields": {
'get': {
"type": "FunctionType",
"name": 'get',
"returns": {
"type": "ListType",
"empty": False,
"subtype": {"type": "NumType"}
}
},
'get_utility': {
"type": "FunctionType",
"name": 'get_utility',
"returns":
{"type": "ListType", "subtype":
{"type": "DictType", "literals": [{"type": "LiteralStr", "value": 'Utility'}, {"type": "LiteralStr", "value": 'Demand'}, {"type": "LiteralStr", "value": 'Sources'}, {"type": "LiteralStr", "value": 'Uses'}, {"type": "LiteralStr", "value": 'Revenues'}, {"type": "LiteralStr", "value": 'Revenue'}, {"type": "LiteralStr", "value": 'Retail'}], "values": [
{"type": "DictType", "literals": [{"type": "LiteralStr", "value": 'Number'}, {"type": "LiteralStr", "value": 'Name'}, {"type": "LiteralStr", "value": 'State'}, {"type": "LiteralStr", "value": 'Type'}], "values": [
{"type": "NumType"},
{"type": "StrType"},
{"type": "StrType"},
{"type": "StrType"}]},
{"type": "DictType", "literals": [{"type": "LiteralStr", "value": 'Summer Peak'}, {"type": "LiteralStr", "value": 'Winter Peak'}], "values": [
{"type": "NumType"},
{"type": "NumType"}]},
{"type": "DictType", "literals": [{"type": "LiteralStr", "value": 'Generation'}, {"type": "LiteralStr", "value": 'Purchased'}, {"type": "LiteralStr", "value": 'Other'}, {"type": "LiteralStr", "value": 'Total'}], "values": [
{"type": "NumType"},
{"type": "NumType"},
{"type": "NumType"},
{"type": "NumType"}]},
{"type": "DictType", "literals": [{"type": "LiteralStr", "value": 'Retail'}, {"type": "LiteralStr", "value": 'Resale'}, {"type": "LiteralStr", "value": 'No Charge'}, {"type": "LiteralStr", "value": 'Consumed'}, {"type": "LiteralStr", "value": 'Losses'}, {"type": "LiteralStr", "value": 'Total'}], "values": [
{"type": "NumType"},
{"type": "NumType"},
{"type": "NumType"},
{"type": "NumType"},
{"type": "NumType"},
{"type": "NumType"}]},
{"type": "DictType", "literals": [{"type": "LiteralStr", "value": 'Retail'}], "values": [
{"type": "NumType"}]},
{"type": "DictType", "literals": [{"type": "LiteralStr", "value": 'Delivery'}, {"type": "LiteralStr", "value": 'Resale'}, {"type": "LiteralStr", "value": 'Adjustments'}, {"type": "LiteralStr", "value": 'Transmission'}, {"type": "LiteralStr", "value": 'Other'}, {"type": "LiteralStr", "value": 'Total'}], "values": [
{"type": "NumType"},
{"type": "NumType"},
{"type": "NumType"},
{"type": "NumType"},
{"type": "NumType"},
{"type": "NumType"}]},
{"type": "DictType", "literals": [{"type": "LiteralStr", "value": 'Residential'}, {"type": "LiteralStr", "value": 'Commercial'}, {"type": "LiteralStr", "value": 'Industrial'}, {"type": "LiteralStr", "value": 'Transportation'}, {"type": "LiteralStr", "value": 'Total'}], "values": [
{"type": "DictType", "literals": [{"type": "LiteralStr", "value": 'Revenue'}, {"type": "LiteralStr", "value": 'Sales'}, {"type": "LiteralStr", "value": 'Customers'}], "values": [
{"type": "NumType"},
{"type": "NumType"},
{"type": "NumType"}]},
{"type": "DictType", "literals": [{"type": "LiteralStr", "value": 'Revenue'}, {"type": "LiteralStr", "value": 'Sales'}, {"type": "LiteralStr", "value": 'Customers'}], "values": [
{"type": "NumType"},
{"type": "NumType"},
{"type": "NumType"}]},
{"type": "DictType", "literals": [{"type": "LiteralStr", "value": 'Revenue'}, {"type": "LiteralStr", "value": 'Sales'}, {"type": "LiteralStr", "value": 'Customers'}], "values": [
{"type": "NumType"},
{"type": "NumType"},
{"type": "NumType"}]},
{"type": "DictType", "literals": [{"type": "LiteralStr", "value": 'Revenue'}, {"type": "LiteralStr", "value": 'Sales'}, {"type": "LiteralStr", "value": 'Customers'}], "values": [
{"type": "NumType"},
{"type": "NumType"},
{"type": "NumType"}]},
{"type": "DictType", "literals": [{"type": "LiteralStr", "value": 'Revenue'}, {"type": "LiteralStr", "value": 'Sales'}, {"type": "LiteralStr", "value": 'Customers'}], "values": [
{"type": "NumType"},
{"type": "NumType"},
{"type": "NumType"}]}]}]}}
},
}
}
class _Constants(object):
'''
Global singleton object to hide some of the constants; some IDEs reveal
internal module details very aggressively, and there's no other way
to hide stuff.
'''
class DatasetException(Exception):
''' Thrown when there is an error loading the dataset for some reason.'''
_Constants._DATABASE_NAME = _os.path.join(_os.path.dirname(__file__),
"electricity.data")
if not _os.access(_Constants._DATABASE_NAME, _os.F_OK):
raise DatasetException(("Error! Could not find a \"{0}\" file. "
"Make sure that there is a \"{0}\" in the "
"same directory as \"{1}.py\"! Spelling is "
"very important here."
).format(_Constants._DATABASE_NAME, __name__))
elif not _os.access(_Constants._DATABASE_NAME, _os.R_OK):
raise DatasetException(("Error! Could not read the \"{0}\" file. "
"Make sure that it readable by changing its "
"permissions. You may need to get help from "
"your instructor."
).format(_Constants._DATABASE_NAME, __name__))
_Constants._DATASET = None
def get_utility():
"""
Retrieves all of the utility.
"""
if _Constants._DATASET is None:
with open(_Constants._DATABASE_NAME, 'rb') as _:
_Constants._DATASET = _pickle.load(_)
return _Constants._DATASET
if __name__ == '__main__':
from pprint import pprint as _pprint
from timeit import default_timer as _default_timer
print(">>> get_utility()")
start_time = _default_timer()
result = get_utility()
print("Time taken: {}".format(_default_timer() - start_time))
_pprint(result[0]) |