Example #1
0
def MetricSearch(dict):
    db = mongoCon.AttDB()
    MET = dict['metric']

    mydoc4 = db.aggregate([{
        '$project': {
            '_id': 0,
            'code': 1,
            'source': 1,
            'report': 1,
            'metric': '$metric'
        }
    }, {
        '$unwind': '$metric'
    }, {
        '$project': {
            '_id': 0,
            'code': 1,
            'source': 1,
            'report': 1,
            'mstd': '$metric.value',
            'mraw': '$metric.name',
            'fact': '$metric.factor'
        }
    }, {
        '$match': {
            'mstd': {
                '$in': [
                    MET,
                ]
            }
        }
    }])
    doc5 = []
    for x in mydoc4:
        doc5.append(x)
    df = pd.DataFrame(data=doc5)
    index = ['code', 'source', 'report', 'mraw', 'mstd', 'fact']
    df = df.reindex(columns=index)
    #print(df)
    name = 'Metric finder for ' + MET + '.csv'
    #df.to_csv(name)
    #print(" CSV outputted to", os.getcwd())
    d = {'name': name, 'df': df}
    return d
Example #2
0
def mnfCheck(dict):
    db = mongoCon.AttDB()
    CODE = dict['code']
    SOURCE = dict['source']
    mydoc4 = db.attributes.aggregate([
            {'$project' : {'_id':0,'code':1,'source':1, 'report':1, 'manufacturer':'$manufacturer'}},
            {'$unwind':'$manufacturer'},
            {'$project':{'_id':0,'code':1,'source':1,'report':1,'std' : '$manufacturer.value','raw': '$manufacturer.name'}},
            {'$match':{'code':{'$in':[CODE,]},'source':{'$in':[SOURCE,]}}}])
    doc5 = []
    for x in mydoc4:
         doc5.append(x)
    df = pd.DataFrame(data =doc5)
    index = ['code', 'source', 'report', 'raw', 'std']
    df = df.reindex(columns = index)
    name= 'MNF check for '+CODE+ ' '+SOURCE+'.csv'
    d = {'name':name, 'df':df}
    return d
Example #3
0
def ChannelCheck(dict):  
    db = mongoCon.AttDB()
    CODE = dict['code']
    REPORT = dict['report']
    SOURCE = dict['source']
    mydoc6 = db.attributes.aggregate([{'$project':{'_id':0, 'code':1, 'source':1, 'report':1, 'channel':'$channel'}},
                                      {'$unwind':'$channel'},
                                      {'$project':{'_id':0, 'code':1, 'source':1, 'report':1, 'std' : '$channel.value', 'raw' : '$channel.name'}}])
    Channel_report = []
    for x in mydoc6:
         Channel_report.append(x)
    df = pd.DataFrame(data =Channel_report)
    index = ['source', 'code', 'raw', 'std']
    header = [np.array(df['code']),np.array(index)]
    df = df.reindex(columns = index)
    name= 'channel check for '+CODE+ ' '+REPORT+'.csv'
    d = {'name':name, 'df':df}
    return d        
Example #4
0
def brandSearch(dict):
    db = mongoCon.AttDB()
    BRD = dict['brand']
    mydoc4 = db.aggregate([{
        '$project': {
            '_id': 0,
            'code': 1,
            'source': 1,
            'report': 1,
            'brand': '$brand'
        }
    }, {
        '$unwind': '$brand'
    }, {
        '$project': {
            '_id': 0,
            'code': 1,
            'source': 1,
            'report': 1,
            'bstd': '$brand.value',
            'braw': '$brand.name',
        }
    }, {
        '$match': {
            'bstd': {
                '$in': [
                    BRD,
                ]
            }
        }
    }])
    doc5 = []
    for x in mydoc4:
        doc5.append(x)
    df = pd.DataFrame(data=doc5)
    index = ['code', 'source', 'report', 'braw', 'bstd']
    df = df.reindex(columns=index)

    #print(df)
    name = 'Brand finder for ' + BRD + '.csv'
    #df.to_csv(name)
    #print(" CSV outputted to", os.getcwd())
    d = {'name': name, 'df': df}
    return d
Example #5
0
def ChannelSearch(dict):
    db = mongoCon.AttDB()
    CH = dict['channel']

    mydoc4 = db.aggregate([{
        '$project': {
            '_id': 0,
            'code': 1,
            'source': 1,
            'report': 1,
            'channel': '$channel'
        }
    }, {
        '$unwind': '$channel'
    }, {
        '$project': {
            '_id': 0,
            'code': 1,
            'source': 1,
            'report': 1,
            'mstd': '$channel.value',
            'mraw': '$channel.name'
        }
    }, {
        '$match': {
            'mstd': {
                '$in': [
                    CH,
                ]
            }
        }
    }])
    doc5 = []
    for x in mydoc4:
        doc5.append(x)
    df = pd.DataFrame(data=doc5)
    index = ['code', 'source', 'report', 'mraw', 'mstd']
    df = df.reindex(columns=index)
    #print(df)
    name = 'Channel finder for ' + CH + '.csv'
    #df.to_csv(name)
    #print(" CSV outputted to", os.getcwd())
    d = {'name': name, 'df': df}
    return d
Example #6
0
def attributeCheck(dict):  
    db = mongoCon.AttDB()
    CODE = dict['code']
    REPORT = dict['report']
    SOURCE = dict['source']
    mydoc4 = db.attributes.aggregate([{'$project' : {'_id':0,'code':1,'source':1, 'report':1, 'attribute':'$attribute'}},
                                      {'$unwind':'$attribute'},
                                      {'$project':{'_id':0,'code':1,'source':1,'report':1,'std' : '$attribute.value','raw': '$attribute.name'}},
                                      {'$match':{'code':{'$in':[CODE,]},'source':{'$in':[SOURCE,]}}}])
    doc5 = []
    for x in mydoc4:
         doc5.append(x)
    print("complete3")
    df = pd.DataFrame(data =doc5)
    index = ['code', 'source', 'report', 'raw', 'std']
    df = df.reindex(columns = index)
    df =df.pivot_table(index = 'raw',columns = 'report', values= 'std', aggfunc=lambda x: ' '.join(str(v) for v in x) )
    d = {'name':name, 'df':df}
    return d
Example #7
0
def recordCheck(dict):
    db = mongoCon.AttDB()
    CODE = dict['code']
    SOURCE = dict['source']
    mydoc4 = db.attributes.aggregate([{'$project' : {'_id':0,'code':1,'source':1, 'report':1, 'record':'$record'}},
                                    {'$unwind':'$record'},
                                    {'$project':{'_id':0,'code':1,'source':1,'report':1,'std' : '$record.value','raw': '$record.name'}},
                                    {'$match':{'code':{'$in':[CODE,]},'source':{'$in':[SOURCE,]}}}])
    recordReport= []
    for x in mydoc4:
         recordReport.append(x)
    df = pd.DataFrame(data =recordReport)
    index = ['source', 'report', 'raw', 'std','fact']
    header = [np.array(df['report']),np.array(index)]
    df = df.reindex(columns = index)
    #df =df.pivot(index = 'raw',columns = 'report', values= ['std', 'fact'] )
    df =df.pivot_table(index = 'raw',columns = 'report', values= ['std', 'fact'], aggfunc=lambda x: ' '.join(str(v) for v in x) )
    name= 'record check for '+CODE+ ' '+SOURCE+'.csv'
    d = {'name':name, 'df':df}
    return d