Skip to main content

A description of your project

Project description

villaInventorySdk

full docs here https://thanakijwanavit.github.io/villa-inventory-sdk/

Install

pip install villaInventorySdk

How to use

Uploading a large amount of data

sample input

from villaPricingSdk.price import PricingSdk
from random import randrange
import boto3, time, json
from dataclasses import dataclass
from dataclasses_json import dataclass_json
from datetime import datetime
import pandas as pd
from nicHelper.dictUtil import printDict
sampleInput =  [
               {
                  'cprcode': 9,
                  'brcode': 1000,
                  'price': 50
                },
               {
                  'cprcode': 4,
                  'brcode': 1000,
                  'price': 35
               },
                {
                  'cprcode': 3,
                  'brcode': 1003,
                  'price': 36,
               }
              ]
def getDf(input_:dict):
  return pd.DataFrame(input_)

df = getDf(sampleInput)
df
<style scoped> .dataframe tbody tr th:only-of-type { vertical-align: middle; }
.dataframe tbody tr th {
    vertical-align: top;
}

.dataframe thead th {
    text-align: right;
}
</style>
cprcode brcode price
0 9 1000 50
1 4 1000 35
2 3 1003 36

Upload data

init sdk

Update price

%%time
key = 'test'
r = sdk.uploadDf(df, key = key)
if r.status_code >= 400: raise Exception(r.json())
sdk.ingestData(key = key)
signed url is 
url : https://pr
fields
 key : test
 AWSAccessKeyId : ASIAVX4Z5T
 x-amz-security-token : IQoJb3JpZ2
 policy : eyJleHBpcm
 signature : kgDRy1etYA
CPU times: user 44.1 ms, sys: 4.2 ms, total: 48.3 ms
Wall time: 5.47 s





{'body': '{"cprcode":{"0":9,"1":4,"2":3},"brcode":{"0":1000,"1":1000,"2":1003},"price":{"0":50,"1":35,"2":36}}',
 'statusCode': 200,
 'headers': {'Access-Control-Allow-Headers': '*',
  'Access-Control-Allow-Origin': '*',
  'Access-Control-Allow-Methods': '*'}}

Query single product

%%time
sdk.querySingleProduct2(cprcode=1234)
succesfully get url, returning pandas
CPU times: user 20.5 ms, sys: 0 ns, total: 20.5 ms
Wall time: 2.69 s
<style scoped> .dataframe tbody tr th:only-of-type { vertical-align: middle; }
.dataframe tbody tr th {
    vertical-align: top;
}

.dataframe thead th {
    text-align: right;
}
</style>
cprcode brcode price
4 1234.0 1000.0 123.0

Query Branch

%%time
sdk.branchQuery(1000)
---------------------------------------------------------------------------

KeyError                                  Traceback (most recent call last)

<timed eval> in <module>


~/SageMaker/.persisted_conda/python38/lib/python3.8/site-packages/nicHelper/wrappers.py in wrapper(self, *args, **kwargs)
     12         @wraps(func)
     13         def wrapper(self, *args, **kwargs):
---> 14             return func(self, *args, **kwargs)
     15         setattr(cls, func.__name__, wrapper)
     16         # Note we are not binding func, but wrapper which accepts self but does exactly the same as func


~/SageMaker/stacks/villaMaster/villa-master-dev/price/villa-price-sdk/villaPricingSdk/price.py in branchQuery(self, brcode, cprcodes)
    151   })
    152   rawReturn = lambda_.invoke(functionName=self.endpoint.queryBranch(), input = payload)
--> 153   parsedReturn = Response.parseBody(rawReturn)
    154   return pd.read_feather(parsedReturn['url'])
    155 


~/SageMaker/.persisted_conda/python38/lib/python3.8/site-packages/awsSchema/apigateway.py in parseBody(cls, dictInput)
     22   @classmethod
     23   def parseBody(cls, dictInput:dict):
---> 24     response = cls.fromDict(dictInput)
     25     return response.body
     26 


~/SageMaker/.persisted_conda/python38/lib/python3.8/site-packages/awsSchema/apigateway.py in fromDict(cls, dictInput)
     31       dictInput should follow apigateway proxy integration
     32     '''
---> 33     body = dictInput.pop('body')
     34     return cls(
     35       body = json.loads(body),


KeyError: 'body'

Query All

%%time
sdk.queryAll2()
succesfully get url, returning pandas
CPU times: user 17.1 ms, sys: 137 µs, total: 17.2 ms
Wall time: 221 ms
<style scoped> .dataframe tbody tr th:only-of-type { vertical-align: middle; }
.dataframe tbody tr th {
    vertical-align: top;
}

.dataframe thead th {
    text-align: right;
}
</style>
cprcode brcode price
0 10806.0 1010.0 513.0
1 89190.0 1028.0 869.0
2 41962.0 1021.0 920.0
3 88179.0 1004.0 725.0
4 1234.0 1000.0 123.0
5 12345.0 1000.0 345.0
6 19163.0 1027.0 745.0
7 55427.0 1022.0 561.0
8 35004.0 1002.0 625.0
9 4.0 1000.0 35.0
10 4.0 1000.0 35.0
11 4.0 1000.0 35.0
12 4.0 1000.0 35.0
13 9.0 1000.0 50.0
14 9.0 1000.0 50.0
15 9.0 1000.0 50.0
16 9.0 1000.0 50.0
17 23505.0 1000.0 187.0
18 3.0 1003.0 36.0
19 3.0 1003.0 36.0
20 71386.0 1017.0 470.0
21 69721.0 1006.0 843.0

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

villaPricingSdk-0.0.2.tar.gz (17.2 kB view hashes)

Uploaded Source

Built Distribution

villaPricingSdk-0.0.2-py3-none-any.whl (18.7 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page