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

initial commit of module for parsing hackey_allocations

parents
from .allocation import allocation
class allocation():
def __init__(self):
self._data = None
def load(self,url='https://gitlab.erc.monash.edu.au/hpc-team/hackey_allocations/raw/master/allocations/data.yaml'):
import yaml
import requests
r=requests.get(url,verify=False)
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:
now=datetime.datetime.now()
try:
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']
else:
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='https://gitlab.erc.monash.edu.au/hpc_team/hackey_allocations/latest/allocations/data.yaml'):
import yaml
with open('/home/debian/hackey_allocations/allocations/data.yaml','r') as f:
self._data = yaml.load(f.read())
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