Working on persistence api
This commit is contained in:
@@ -2,6 +2,7 @@ import boto3
|
||||
import simplejson as json
|
||||
import decimal
|
||||
|
||||
|
||||
class DecimalEncoder(json.JSONEncoder):
|
||||
def default(self, o):
|
||||
if isinstance(o, decimal.Decimal):
|
||||
@@ -30,16 +31,15 @@ class Persistence:
|
||||
table = self.db.Table(self.table)
|
||||
|
||||
response = table.scan()
|
||||
result = []
|
||||
result = response['Items']
|
||||
|
||||
while 'LastEvaluatedKey' in response:
|
||||
for i in response['Items']:
|
||||
result.append(i)
|
||||
response = table.scan(
|
||||
ExclusiveStartKey=response['LastEvaluatedKey']
|
||||
)
|
||||
|
||||
for i in response['Items']:
|
||||
result.append(i)
|
||||
|
||||
return result
|
||||
|
||||
def load(self, sample):
|
||||
|
||||
@@ -19,11 +19,15 @@ def names(event, context):
|
||||
"""
|
||||
table = Persistence(os.environ['strategyTable'])
|
||||
|
||||
# map results and hide informations
|
||||
data = list(map(lambda x: {'name': x['name'], 'public': x['public'], 'user': x['user']}, table.list()))
|
||||
|
||||
return {
|
||||
"statusCode": 200,
|
||||
"body": json.dumps(table.list())
|
||||
"body": json.dumps(data)
|
||||
}
|
||||
|
||||
|
||||
def performance(event, context):
|
||||
"""
|
||||
returns the performance of the specified strategy
|
||||
@@ -71,9 +75,8 @@ def submit(event, context):
|
||||
# try to load the strategy
|
||||
StrategyResolver().compile(data['name'], strategy)
|
||||
|
||||
# generate id
|
||||
data['id'] = str(uuid.uuid4())
|
||||
data['time'] = int(time.time() * 1000)
|
||||
data['type'] = "strategy"
|
||||
|
||||
# save to DB
|
||||
table = Persistence(os.environ['strategyTable'])
|
||||
|
||||
Reference in New Issue
Block a user