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 details)

Uploaded Source

Built Distribution

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

Uploaded Python 3

File details

Details for the file villaPricingSdk-0.0.2.tar.gz.

File metadata

  • Download URL: villaPricingSdk-0.0.2.tar.gz
  • Upload date:
  • Size: 17.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.23.0 setuptools/49.6.0.post20201009 requests-toolbelt/0.9.1 tqdm/4.51.0 CPython/3.8.6

File hashes

Hashes for villaPricingSdk-0.0.2.tar.gz
Algorithm Hash digest
SHA256 68e64da801e436bcffe7c652fbefadd3edd69f0123e7428839bb1894fdd9ca8d
MD5 9f6c29549792dbac1e6c4b4aa7fa9270
BLAKE2b-256 481226b1b07df44e55ad14a86448ca2e3cd3133c50f86d6a66effda20bb2aed2

See more details on using hashes here.

File details

Details for the file villaPricingSdk-0.0.2-py3-none-any.whl.

File metadata

  • Download URL: villaPricingSdk-0.0.2-py3-none-any.whl
  • Upload date:
  • Size: 18.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.23.0 setuptools/49.6.0.post20201009 requests-toolbelt/0.9.1 tqdm/4.51.0 CPython/3.8.6

File hashes

Hashes for villaPricingSdk-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 46720bf13a5c4148e765ec6741eaa6094e47b3d8e218c2a98eb6dc27060cb6f6
MD5 e4d74423a9306645488fc1056c3104e0
BLAKE2b-256 94779f3bbca75180049c15aaf4254b0116fb45df8f18e6c51a1fdf8366d95340

See more details on using hashes here.

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