Untitled

mail@pastecode.io avatar
unknown
plain_text
a year ago
2.4 kB
3
Indexable
from models.cache_store import cache_store
from models.cache_store_by_username import cache_store_by_username
from models.cache_store_by_date import cache_store_by_date
from models.indexes import indexes
from models.columns import columns as tablecolumns
from datetime import datetime, timedelta, timezone
from dateutil.relativedelta import relativedelta
from pandas.io.json import json_normalize
import json
from config.logger import configlogfile

from flask import jsonify, make_response
import pandas as pd
import sys
import gc
import uuid
import pytz

"""
This function is used to fetch cache details based on valueType and key
"""


def getData(payLoad, configvalues):
    from config.logger import configlogfile
    logging = configlogfile()
    logging.info("Started to fetch the records for " + str(payLoad))

    cacheStore = []
    try:
        payLoad = payLoad.to_dict()
        columnMapping = json.loads(configvalues.get('apiconfiguration', 'columnMapping', raw=True))
        reversecolumnMapping = {y: x for x, y in columnMapping.items()}
        validColumns = json.loads(configvalues.get('apiconfiguration', 'validColumns', raw=True))
        datecolumns = json.loads(configvalues.get('apiconfiguration', 'dateColumns', raw=True))
        datecolumns.append('createdtime')  # Add 'createdtime' column
        logging.debug('Arguments -' + str(payLoad))

        # Rest of the code...

        for i in range(len(partitioncolstofilter)):
            if i == 0:
                if partitioncolstofilter[i] in datecolumns:
                    query = 'global cacheStoreRecords;cacheStoreRecords=cache_store.objects().filter(' + \
                        partitioncolstofilter[i] + '=datetime.strptime(\'' + \
                        str((payLoad[partitioncolstofilter[i]])) + '\',\'%Y-%m-%d\'));'
                else:
                    query = 'global cacheStoreRecords;cacheStoreRecords=cache_store.objects().filter(' + \
                        partitioncolstofilter[i] + '=\'' + str(payLoad[partitioncolstofilter[i]]) + '\');'
            else:
                if partitioncolstofilter[i] in datecolumns:
                    query = 'global cacheStoreRecords;cacheStoreRecords=cacheStoreRecords.filter(' + \
                        partitioncolstofilter[i] + \
                        '=datetime.strptime(\'' + str(
                            (payLoad[partitioncolstofilter[i]])) + '\',\'%Y-%m-%d\'));'