# AUTOGENERATED! DO NOT EDIT! File to edit: helper.ipynb (unless otherwise specified).

__all__ = ['DatabaseHelper']

# Cell
import pandas as pd
from datetime import datetime
import pickle, json , boto3, zlib, os, logging
from s3bz.s3bz import S3

# Cell
class DatabaseHelper:
  class Helper:
    @staticmethod
    def groupByProduct(data):
      return [{row['iprcode']: row} for row in data]

      df = pd.DataFrame(data)
      gprcode = df.groupby('iprcode')
      # group by ib_prcode, then ib_brcode, add timestamp as well
      res = gprcode.agg(list).apply(lambda x: {
            k:v for k,v in zip(
                x['ib_brcode'], [
                  {
                    'ib_cf_qty': int(qty),
                    'new_ib_bs_stock_cv': int(new),
                    'lastUpdate' : datetime.now().timestamp()
                  }
                  for qty,new in zip(x['ib_cf_qty'], x['new_ib_vs_stock_cv'])
                ]
              )
          } , axis = 1)
      return res.to_dict()
    @staticmethod
    def setUpdateAll():
      return list(item.setUpdate() for item in Database.scan())

    @staticmethod
    def iteratorToInvDict(data):
      return {item.ib_prcode:item.inventory for item in data}

    @staticmethod
    def stripDict(data:dict):
      return {k: v.strip() if type(v) == str else v for k,v in data.items()}