@ -192,18 +192,23 @@ class Apex :
@staticmethod
def scalar ( item ) :
_df = item [ ' data ' ]
name = _df . columns . tolist ( ) [ 0 ]
value = _df [ name ] . values . round ( 2 ) [ 0 ]
value = ' 0 '
unit = ' '
html = ' <div class= " scalar " ><div class= " value " >:value</div><div class= " label " >:label</div></div> '
if value > 999 and value < 1000000 :
value = " " . join ( [ str ( np . divide ( value , 1000 ) . round ( 2 ) ) , " K " ] )
elif value > 999999 :
#@ Think of considering the case of a billion ...
value = " " . join ( [ str ( np . divide ( value , 1000000 ) . round ( 2 ) ) , " M " ] )
else :
value = str ( value )
unit = name . replace ( ' _ ' , ' ' ) if ' unit ' not in item else item [ ' unit ' ]
if _df . shape [ 0 ] > 0 :
print ( _df )
print ( ' _____________________________________ ' )
name = _df . columns . tolist ( ) [ 0 ]
value = _df [ name ] . values [ 0 ]
if value > 999 and value < 1000000 :
value = " " . join ( [ str ( np . divide ( value , 1000 ) . round ( 2 ) ) , " K " ] )
elif value > 999999 :
#@ Think of considering the case of a billion ...
value = " " . join ( [ str ( np . divide ( value , 1000000 ) . round ( 2 ) ) , " M " ] )
else :
value = str ( value )
unit = name . replace ( ' _ ' , ' ' ) if ' unit ' not in item else item [ ' unit ' ]
return { ' html ' : html . replace ( ' :value ' , value ) . replace ( " :label " , unit ) }
@staticmethod
def column ( item ) :
@ -319,8 +324,9 @@ class Apex :
values = df [ x_cols ] . values . round ( 2 ) . tolist ( )
else :
labels = [ name . upper ( ) . replace ( ' _ ' , ' ' ) for name in df . columns . tolist ( ) ]
df = df . astype ( float )
values = df . values . round ( 2 ) . tolist ( ) [ 0 ] if df . shape [ 1 ] > 1 else df . values . round ( 2 ) . tolist ( )
# df = df.astype(float)
# values = df.values.round(2).tolist()[0] if df.shape[1] > 1 else df.values.round(2).tolist()
values = df [ [ name for name in df . columns if df [ name ] . dtype in [ float , int ] ] ] . values . round ( 2 ) . tolist ( )
colors = COLORS [ : len ( values ) ]
options = { " series " : values , " colors " : colors , " labels " : labels , " dataLabels " : { " enabled " : True , " style " : { " colors " : [ " #000000 " ] } , " dropShadow " : { " enabled " : False } } , " chart " : { " type " : " donut " , " width " : 200 } , " plotOptions " : { " pie " : { " customScale " : .9 } } , " legend " : { " position " : " right " } }
@ -343,10 +349,10 @@ class engine :
self . store_config = _config [ ' store ' ]
self . info = _config [ ' analytics ' ]
_args = self . store_config
if self . store_config [ ' type ' ] == ' mongo.MongoWriter ' :
_args [ ' type ' ] = ' mongo.MongoReader '
else :
_args [ ' type ' ] = ' disk.SQLiteReader '
if ' type ' not in self . store_config :
#
# This is the newer version of data-transport
self . store_config [ ' context ' ] = ' read '
self . store_config = _args ;
def filter ( self , * * args ) :
@ -367,8 +373,8 @@ class engine :
# conn = lite.connect(self.store_config['args']['path'],isolation_level=None)
# conn.create_aggregate("stdev",1,stdev)
DB_TYPE = ' mongo ' if ( type ( self . reader ) == transport . mongo . MongoReader ) else ' sql '
if DB_TYPE == ' mongo ' :
self . store_config [ ' args ' ] [ ' doc ' ] = args [ ' type ' ]
# if DB_TYPE == 'mongo' :
# self.store_config['args']['doc'] = args['type' ]
self . reader = transport . factory . instance ( * * self . store_config )
r = [ ]
@ -414,20 +420,8 @@ class engine :
_analytics = [ _analytics [ index ] ]
_info = list ( _analytics ) if ' filter ' not in args else [ item for item in analytics if args [ ' filter ' ] == item [ ' id ' ] ]
# conn = lite.connect(self.store_config['args']['path'],isolation_level=None)
# conn.create_aggregate("stdev",1,stdev)
#
# @TODO: Find a better way to handle database variance
#
# DB_TYPE = 'mongo' if (type(self.reader) == transport.mongo.MongoReader) else 'sql'
if ' mongo ' in self . store_config [ ' type ' ] :
DB_TYPE = ' mongo '
else :
DB_TYPE = ' sql '
self . store_config [ ' args ' ] [ ' table ' ] = args [ ' type ' ]
self . reader = transport . factory . instance ( * * self . store_config )
DB_TYPE = ' mongo ' if self . store_config [ ' provider ' ] in [ ' mongodb ' , ' mongo ' ] else ' sql '
r = [ ]
for row in _info :
pipeline = row [ ' pipeline ' ]
@ -440,14 +434,22 @@ class engine :
continue
if DB_TYPE == ' sql ' :
query = { " sql " : query }
else :
query = { DB_TYPE : query }
item [ ' data ' ] = self . reader . read ( * * query ) #item)
_df = self . reader . read ( * * query ) #item)
print ( query )
print ( self . reader )
if ' serialize ' in args :
# item['data'] = json.dumps(item['data'].to_dict(orient='record')) if type(item['data']) == pd.DataFrame else item['data']
item [ ' data ' ] = json . dumps ( item[ ' data ' ] . to_dict ( ' record ' ) ) if type ( item [ ' data ' ] ) == pd . DataFrame else item [ ' data ' ]
item [ ' data ' ] = json . dumps ( _df. to_dict ( orient = ' record ' ) )
else :
item [ ' data ' ] = ( pd . DataFrame ( item [ ' data ' ] ) )
# item['data'] = (pd.DataFrame(item['data']))
item [ ' data ' ] = _df
pass
print ( _df . head ( ) )
break
pipeline [ index ] = item
index + = 1
#