Ejemplo n.º 1
0
            
            
            
    def get_random_outlet_type(self):
        _type = random.randint(0,4)
        
        _type_name = SmartfrenOutletMasterList.RANDOM_OUTLET_TYPE[_type]

        _sub_type_name = ''
        if _type == 1:
            _sub_type = random.randint(0,2)
            _sub_type_name = SmartfrenOutletMasterList.RANDOM_OUTLET_SUBTYPE[_sub_type]
        
        return _type_name, _sub_type_name, _icon
        
    def go_through_facility_types (self, facility, types):
        for obj in FacilityTagMapping.query.filter_by ( facility_id = facility.id ).all():
            db.session.delete(obj)
        db.session.commit()
           
           
        for _type in types:
            if _type:
                tag = FacilityTagMapping()
                tag.facility_id = facility.id
                tag.facility_tag_name = _type
                db.session.add(tag)
        db.session.commit()

manager.add_command('smartfren_outlet_master_list', SmartfrenOutletMasterList())
Ejemplo n.º 2
0
        db.session.commit()

        
    def aggregate_day (self, day, month, year):
        self.delete_tables ( SalesForceBoundaryKPIDaily.__tablename__, year, month, day )     
        db.session.execute('SELECT aggregate_boundary_sales_force_kpi_day_sum(:date_day, :date_month, :date_year)', { 'date_day' : day, 'date_month' : month, 'date_year' : year } )
        db.session.commit()       
    
    def aggregate_week (self, week_date):
        day, month, year = week_date.day, week_date.month, week_date.year
        self.delete_tables ( SalesForceBoundaryKPIWeekly.__tablename__, start_week = week_date )   
        db.session.execute('SELECT aggregate_boundary_sales_force_kpi_week_sum(:date_day, :date_month, :date_year)', {'date_day' : day, 'date_month' : month, 'date_year' : year } )
        db.session.commit()
        
        self.delete_tables ( SalesForceFacilityKPIWeekly.__tablename__, start_week = week_date )         
        db.session.execute('SELECT aggregate_facility_sales_force_week_sum(:date_day, :date_month, :date_year)', { 'date_day' : day, 'date_month' : month, 'date_year' : year } )
        db.session.commit()
        

    def aggregate_year(self, year):
        self.delete_tables ( SalesForceBoundaryKPIYear.__tablename__, year )        
        db.session.execute('SELECT aggregate_boundary_sales_force_kpi_year_sum(:date_year)', { 'date_year' : year } )
        db.session.commit()
        
        self.delete_tables ( SalesForceFacilityKPIYear.__tablename__, year )            
        db.session.execute('SELECT aggregate_facility_sales_force_kpi_year_sum(:date_year)', { 'date_year' : year } )
        db.session.commit()

        
manager.add_command('smartfren_salesforce_kpi', SmartfrenSalesForceKPI())
Ejemplo n.º 3
0
import traceback
from configparser import ConfigParser

from manage import (manager, MyServer)

try:
    config_parser = ConfigParser()
    config_parser.read("conf/flask_project.ini")
    sever_type = config_parser.get("xx_server", "type")
    if sever_type == "dev":
        print("run with DebugConfig")
        manager.add_command('run', MyServer())
    else:
        manager.add_command('run', MyServer())
except Exception as e:
    print(traceback.format_exc())

if __name__ == '__main__':
    manager.run()
'''
uwsgi --http :8080 --wsgi-file manage.py run
'''
Ejemplo n.º 4
0
        print 'Uploading postgis'
        f = open( os.path.join(postgis, 'postgis.sql') )
        s  = f.read()
        f.close()
        db.session.execute(s)

        f = open( os.path.join(postgis, 'spatial_ref_sys.sql') )
        s  = f.read()
        f.close()
        db.session.execute(s)
        
        print 'Creating all Flask Tables...'
        db.create_all()
        
        

        _ = []
        sql_path = os.path.join('sql', 'partition')
        for obj in os.listdir(sql_path):
            _.append(obj)
        
        for obj in _:
            print 'uploading %s' % ( obj, )
            f = open (os.path.join(sql_path, obj),'r')
            s = f.read()
            f.close()
            db.session.execute(s)
        print 'Done'
            
manager.add_command('create_db', CreateDB())
Ejemplo n.º 5
0
                        encoded = encoder.encode([i[::-1] for i in poly.geom.coords(db.session)[0]])['points']
                        poly.encoded_poly = encoded
                        db.session.add( poly )
                                    
                db.session.commit()
                

    def dump(self, filename):
        with open(filename, 'w') as f:
            list_writer = csv.writer(f, delimiter=',')
            for _b in Boundary.query.filter_by( level_id = 1 ):
                
                
                boundary_id, boundary_name, boundary_parent_id, boundary_level_id, polygons_filename = _b.id, _b.name, _b.parent_id, _b.level_id, 'polygons_%s.json' % (_b.id,)
                list_writer.writerow([boundary_id, boundary_name, boundary_parent_id, boundary_level_id, polygons_filename])
                
                all_polygons = []
                for poly in BoundaryPolygons.query.filter_by(boundary_id = boundary_id):
                    polygons =  [ i for i in poly.geom.coords(db.session)[0]]
                    all_polygons.append(polygons)
                open(polygons_filename,'w').write(simplejson.dumps(all_polygons))
                
                
            # end for
        # end with
        
    # end def           
            

manager.add_command('smartfren_national_master_list', SmartfrenRegionMasterList())
Ejemplo n.º 6
0
                        encoded = encoder.encode([i[::-1] for i in poly.geom.coords(db.session)[0]])['points']
                        poly.encoded_poly = encoded
                        db.session.add( poly )
                                    
                db.session.commit()
                

    def dump(self, filename):
        with open(filename, 'w') as f:
            list_writer = csv.writer(f, delimiter=',')
            for _b in Boundary.query.filter_by( level_id = 1 ):
                
                
                boundary_id, boundary_name, boundary_parent_id, boundary_level_id, polygons_filename = _b.id, _b.name, _b.parent_id, _b.level_id, 'polygons_%s.json' % (_b.id,)
                list_writer.writerow([boundary_id, boundary_name, boundary_parent_id, boundary_level_id, polygons_filename])
                
                all_polygons = []
                for poly in BoundaryPolygons.query.filter_by(boundary_id = boundary_id):
                    polygons =  [ i for i in poly.geom.coords(db.session)[0]]
                    all_polygons.append(polygons)
                open(polygons_filename,'w').write(simplejson.dumps(all_polygons))
                
                
            # end for
        # end with
        
    # end def           
            

manager.add_command('smartfren_kpi_list', SmartfrenRegionMasterList())
Ejemplo n.º 7
0
    s += t % { 'tablename' : Month.__tablename__, 'id' : 5, 'name' : "May"}

    t = '''INSERT INTO %(tablename)s ( id, name ) VALUES ( %(id)s, '%(name)s');\n'''
    s += t % { 'tablename' : Month.__tablename__, 'id' : 6, 'name' : "June"}

    
    t = '''INSERT INTO %(tablename)s ( id, name ) VALUES ( %(id)s, '%(name)s');\n'''
    s += t % { 'tablename' : Month.__tablename__, 'id' : 7, 'name' : "July"}

    t = '''INSERT INTO %(tablename)s ( id, name ) VALUES ( %(id)s, '%(name)s');\n'''
    s += t % { 'tablename' : Month.__tablename__, 'id' : 8, 'name' : "August"}

    t = '''INSERT INTO %(tablename)s ( id, name ) VALUES ( %(id)s, '%(name)s');\n'''
    s += t % { 'tablename' : Month.__tablename__, 'id' : 9, 'name' : "September"}
    
    t = '''INSERT INTO %(tablename)s ( id, name ) VALUES ( %(id)s, '%(name)s');\n'''
    s += t % { 'tablename' : Month.__tablename__, 'id' : 10, 'name' : "October"}

   
    t = '''INSERT INTO %(tablename)s ( id, name ) VALUES ( %(id)s, '%(name)s');\n'''
    s += t % { 'tablename' : Month.__tablename__, 'id' : 11, 'name' : "November"}

    t = '''INSERT INTO %(tablename)s ( id, name ) VALUES ( %(id)s, '%(name)s');\n'''
    s += t % { 'tablename' : Month.__tablename__, 'id' : 12, 'name' : "December"}

    
    return s    
            

manager.add_command('smartfren_initdb', SmartfrenInitDB())
Ejemplo n.º 8
0
        db.session.execute('SELECT aggregate_facility_productgroup_week_sum(:date_day, :date_month, :date_year)', { 'date_day' : day, 'date_month' : month, 'date_year' : year } )
        db.session.commit()
        
        self.delete_tables ( SumBoundaryProductWeek.__tablename__, start_week = week_date )              
        db.session.execute('SELECT aggregate_boundary_product_week_sum(:date_day, :date_month, :date_year)', { 'date_day' : day, 'date_month' : month, 'date_year' : year } )
        db.session.commit()

        self.delete_tables ( SumBoundaryProductGroupWeek.__tablename__, start_week = week_date ) 
        db.session.execute('SELECT aggregate_boundary_productgroup_week_sum(:date_day, :date_month, :date_year)', { 'date_day' : day, 'date_month' : month, 'date_year' : year } )
        db.session.commit()
            
    def aggregate_year(self, year):
        self.delete_tables ( SumFacilityProductYear.__tablename__, year )        
        db.session.execute('SELECT aggregate_facility_product_year_sum(:date_year)', { 'date_year' : year } )
        db.session.commit()
        
        self.delete_tables ( SumFacilityProductGroupYear.__tablename__, year )            
        db.session.execute('SELECT aggregate_facility_productgroup_year_sum(:date_year)', { 'date_year' : year } )
        db.session.commit()
        
        self.delete_tables ( SumBoundaryProductYear.__tablename__, year )          
        db.session.execute('SELECT aggregate_boundary_product_year_sum(:date_year)', { 'date_year' : year } )
        db.session.commit()
        
        self.delete_tables ( SumBoundaryProductGroupYear.__tablename__, year )       
        db.session.execute('SELECT aggregate_boundary_productgroup_year_sum(:date_year)', { 'date_year' : year } )

        db.session.commit()
        
manager.add_command('smartfren_product_data', SmartfrenProductData())
Ejemplo n.º 9
0
        # end if
        
        logger.setLevel(logging.INFO)
 
        if not source_directory:
            print '--source-directory not specified'
            
        else:
            pf_csv = os.path.join(source_directory, 'product_family_master_list.csv')
            if os.path.exists( pf_csv ):
                _ = factory.getProductFamilies(logger)
                _.load(pf_csv)
                
            p_csv = os.path.join(source_directory, 'product_master_list.csv')
            if os.path.exists( p_csv ):
                _ = factory.getProducts (logger)
                _.load(p_csv)
                
            sfr_csv = os.path.join(source_directory, 'sales_force_role_master_list.csv')
            if os.path.exists( sfr_csv ):
                _ = factory.getSalesForceRoles(logger)
                print 'hi'
                _.load(sfr_csv)

            sf_csv = os.path.join(source_directory, 'sales_force_master_list.csv')
            if os.path.exists( sf_csv ):
                _ = factory.getSalesForce(logger)
                _.load(sf_csv)
                
manager.add_command('smartfren_master_list', SmartfrenMasterList())
Ejemplo n.º 10
0
                        encoded = encoder.encode([i[::-1] for i in poly.geom.coords(db.session)[0]])['points']
                        poly.encoded_poly = encoded
                        db.session.add( poly )
                                    
                db.session.commit()
                


    def dump(self, filename):
        with open(filename, 'w') as f:
            list_writer = csv.writer(f, delimiter=',')
            for _b in Boundary.query.filter_by( level_id = 3 ):
                
                
                boundary_id, boundary_name, boundary_parent_id, boundary_level_id, polygons_filename = _b.id, _b.name, _b.parent_id, _b.level_id, 'polygons_%s.json' % (_b.id,)
                list_writer.writerow([boundary_id, boundary_name, boundary_parent_id, boundary_level_id, polygons_filename])
                
                all_polygons = []
                for poly in BoundaryPolygons.query.filter_by(boundary_id = boundary_id):
                    polygons =  [ i for i in poly.geom.coords(db.session)[0]]
                    all_polygons.append(polygons)
                open(polygons_filename,'w').write(simplejson.dumps(all_polygons))               
                
            # end for
        # end with
        
    # end def           
            

manager.add_command('smartfren_cluster_master_list', SmartfrenClusterMasterList())