Commit d27c8e27 authored by Chris Hines's avatar Chris Hines
Browse files

initial commit of module for parsing hackey_allocations

from .allocation import allocation
class allocation():
def __init__(self):
self._data = None
def load(self,url=''):
import yaml
import requests
self._data = yaml.load(r.text)
def get_group_qty(self,myreduction):
return map(lambda x: (x[0],sum(map(myreduction,x[1]))),self._data.items())
def default_reduction_kernel(self,service,alloc):
import datetime
if 'start' in alloc or 'end' in alloc:
start = datetime.datetime.strptime("{}".format(alloc['start']),'%Y%m%d')
end = datetime.datetime.strptime("{}".format(alloc['end']),'%Y%m%d')
except Exception as e:
print('Invalid date entered')
return 0
if not (start < now and now < end):
return 0
if 'qty' in alloc and alloc['service'] == service:
return alloc['qty']
return 0
def get_groups_by_service(self,service):
# select a function which returns the value of the allocation, it could be dependent on the service name, or the period of validity
# it may perform conversions based on units etc etc etc.
myreduction=lambda x: self.default_reduction_kernel(service,x)
return [(k,v) for (k,v) in self.get_group_qty(myreduction) if v > 0]
class allocation():
def __init__(self):
self._data = None
def load(self,url=''):
import yaml
with open('/home/debian/hackey_allocations/allocations/data.yaml','r') as f:
self._data = yaml.load(
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment