Esempio n. 1
0
def search():
    student_info = request.args.get('data', '')
    info_dict = json.loads(str(student_info))
    assert type(info_dict) is dict
    if len(DatabaseUtil.search_student(g.db, info_dict)) == 2:
        return ''
    else:
        response = literal_eval(DatabaseUtil.search_student(g.db, info_dict))
        return render_template('template.html', response=response)
def search():
    student_info = request.args.get('data', '')
    info_dict = json.loads(str(student_info))
    assert type(info_dict) is dict
    if len(DatabaseUtil.search_student(g.db, info_dict)) == 2:
        return ''
    else:
        response = literal_eval(DatabaseUtil.search_student(g.db, info_dict))
        return render_template('template.html', response=response)
Esempio n. 3
0
    def connect(self):
        self.dbUtil = DatabaseUtil(self.dbFile, self.scenario)
        self.logger = open(os.path.join(self.outDir, 'graphviz.log'), 'w')
        self.setGraphicOptions(False, False)
        self.__log__('--------------------------------------')
        self.__log__('GraphvizDiagramGenerator: connected')
        if (self.scenario):
            outDir = self.qName + '_' + self.scenario + '_graphviz'
        else:
            outDir = self.qName + '_input_graphviz'

        self.outDir = os.path.join(self.outDir, outDir)
        if (not os.path.exists(self.outDir)):
            os.mkdir(self.outDir)
Esempio n. 4
0
def check_exist():
    student_info = request.args.get('data', '')
    info_dict = json.loads(student_info)
    assert type(info_dict) is dict
    response = DatabaseUtil.check_exist(g.db, info_dict)
    r.check_exist(info_dict, response)
    return 'True'
Esempio n. 5
0
def is_working_day(date):
    sql = "SELECT fn_is_holiday('" + date + "')"
    flag = dbu.get_data(sql)[0][0]
    if flag == 'W':
        return True
    else:
        return False
Esempio n. 6
0
def delete():
    student_info = request.args.get('data', '')
    info_dict = json.loads(str(student_info))
    assert type(info_dict) is dict
    data = {'student_id': info_dict['student_id']}
    r.delete_student(data)
    response = DatabaseUtil.delete_student(g.db, info_dict)
    return response
Esempio n. 7
0
def search():
    student_info = request.args.get('data', '')
    info_dict = json.loads(str(student_info))
    assert type(info_dict) is dict
    response = DatabaseUtil.search_student(g.db, info_dict)
    names = literal_eval(response[0])
    rows = literal_eval(response[1])
    return render_template('template.html', names=names, rows=rows)
Esempio n. 8
0
def smartUpdate(end_date=date.today()):
    sql = "SELECT * FROM stockmaster where LAST_UPDATED_DATE < '" + du.convertDateToString(end_date, "%Y-%m-%d") + "'"
    result_set = dbu.query(sql)
    while len(result_set) > 0:
        for each in result_set:
            stock_code = each[0]
            index_indicator = each[2]
            stock_code_163 = each[3]
            stock_code_sina = each[4]
            start_date = each[5]

            logger.info("UPDATING STOCK, STOCK CODE IS " + stock_code)

            if start_date is None:
                start_date = du.convertStringToDate("1990-01-01", "%Y-%m-%d")
            elif start_date == end_date:
                continue
            else:
                start_date = start_date + timedelta(1)

            data = bd.getStockData(stock_code_163, start_date, end_date)

            if len(data) > 0:
                last_updated_date = data[0].split(",")[0]
                bd.insertBasicData(stock_code, data)
                logger.info("INSERT BASIC DATA COMPLETED")
                bd.insertTechData(stock_code, data)
                logger.info("INSERT TECH DATA COMPLETED")
                bd.insertAnalysisData(stock_code, data)
                logger.info("INSERT ANALYSIS DATA COMPLETED")
                bd.updateMasterDate("LAST_UPDATED_DATE", last_updated_date, stock_code_163)
                logger.info("LAST DATE UPDATED")

                if str(index_indicator) == "1":
                    rf = bd.getRecoveryFactor(stock_code_163, stock_code_sina, start_date)
                    bd.insertRecoveryFactor(stock_code, rf)
                    logger.info("INSERT RF DATA COMPLETED")
            else:
                logger.error("NO DATA IS RECEIVED FROM 163")

        result_set = dbu.query(sql)
        if len(result_set) > 0:
            logger.info("NOT ALL STOCKS ARE UPDATED, WAIT 10 MINUTES FOR NEXT UPDATE")
            tm.sleep(10*60)

    return "COMPLETED"
Esempio n. 9
0
def getBROrARs(key, stock_code, date, period):
    sql = (
        "SELECT BRAR_"
        + key
        + " FROM stocktechdata WHERE STOCK_CODE = '"
        + stock_code
        + "' AND DATE <= '"
        + date
        + "' ORDER BY DATE DESC LIMIT "
        + str(period)
    )
    return dbu.query(sql)
Esempio n. 10
0
def check_exist():
    student_info = request.args.get('data', '')
    info_dict = json.loads(student_info)
    assert type(info_dict) is dict
    response = DatabaseUtil.check_exist(g.db, info_dict)
    return response
Esempio n. 11
0
def drop_column():
    student_info = request.args.get('data', '')
    info_dict = json.loads(student_info)
    assert type(info_dict) is dict
    response = DatabaseUtil.drop_column(g.db, info_dict)
    return response
Esempio n. 12
0
def update():
    student_info = request.args.get('data', '')
    info_dict = json.loads(str(student_info))
    assert type(info_dict) is dict
    response = DatabaseUtil.update_student(g.db, info_dict)
    return response
Esempio n. 13
0
def getBasicDataInPeriod(field, stock_code, date, period):
    sql = "SELECT " + field + " FROM stockbasicdata WHERE STOCK_CODE ='" + stock_code + "' AND DATE <='" + date + "' AND VOLUMN <> 0 ORDER BY DATE DESC LIMIT " + str(
        period)
    return dbu.query(sql)
Esempio n. 14
0
def get_basic_data(stock_code, date, time_period):
    sql = 'select * from pdtb_stock_basic_data t where t.code =\'' + stock_code + '\' and t.date <= \'' + date + '\' order by t.date desc limit 0,' + str(
        time_period)
    #print sql
    return dbu.get_pd_data(sql)
Esempio n. 15
0
def callTechInitProc(stock_code):
    dbu.call("init_Stock", (stock_code,))
Esempio n. 16
0
@app.route("/student/delete/", methods=['POST'])
def delete():
    student_info = request.args.get('data', '')
    info_dict = json.loads(str(student_info))
    assert type(info_dict) is dict
    response = DatabaseUtil.delete_student(g.db, info_dict)
    return response


@app.route("/student/check_exist/", methods=['POST'])
def check_exist():
    student_info = request.args.get('data', '')
    info_dict = json.loads(student_info)
    assert type(info_dict) is dict
    response = DatabaseUtil.check_exist(g.db, info_dict)
    return response


if __name__ == "__main__":
    if len(sys.argv) != 2:
        print 'Please input the service number'
        sys.exit(1)
    try:
        global service_number
        service_number = str(sys.argv[1])
    except:
        print 'The input service number not find'
        sys.exit(1)
    DatabaseUtil.setup_database(
        config.get(service_number + ':DATABASE_STUDENT'))
    app.run(host='0.0.0.0', port=int(config.get(service_number + ':PORT')))
Esempio n. 17
0
def before_request():
    g.db = DatabaseUtil.connect_db(
        config.get(service_number + ':DATABASE_STUDENT'))
Esempio n. 18
0
def getStockDate(stock_code, date, offset):
    sql = "SELECT getStockDate('" + stock_code + "', '" + date + "', " + str(offset) + ")"
    return dbu.query(sql)[0][0].strftime("%Y-%m-%d")
Esempio n. 19
0
def pre_miha():
    conn = databaseUtil.create_connection("PredictedMiHA.db")
    rows = databaseUtil.get_miha_rows(conn, 50, 1)
    return render_template('databaseViewer.html', data=rows)
Esempio n. 20
0
def getLowPriceInPeriod(field, stock_code, date, period):
    sql = "SELECT MIN(A." + field + ") FROM (SELECT * FROM stockbasicdata t WHERE t.STOCK_CODE ='" + stock_code + "' AND t.DATE <= '" + date + "' AND t.VOLUMN <> 0 ORDER BY t.DATE DESC LIMIT " + str(
        period) + ") A"
    return dbu.query(sql)[0][0]
Esempio n. 21
0
def getTechDataInPeriod(field, stock_code, date, period):
    sql = "SELECT " + field + " FROM stocktechdata WHERE STOCK_CODE ='" + stock_code + "' AND DATE <='" + date + "' AND SUSPENDED <>'Y' ORDER BY DATE DESC LIMIT " + str(
        period)
    return dbu.query(sql)
Esempio n. 22
0
def isHoliday(date):
    sql = "SELECT isHoliday('" + date + "')"
    return dbu.query(sql)[0][0]
Esempio n. 23
0
def delete():
    student_info = request.args.get('data', '')
    info_dict = json.loads(str(student_info))
    assert type(info_dict) is dict
    response = DatabaseUtil.delete_student(g.db, info_dict)
    return response
Esempio n. 24
0
@app.route("/student/add_column/", methods=['POST'])
def add_column():
    student_info = request.args.get('data', '')
    info_dict = json.loads(student_info)
    assert type(info_dict) is dict
    response = DatabaseUtil.add_column(g.db, info_dict)
    return response

@app.route("/student/drop_column/", methods=['POST'])
def drop_column():
    student_info = request.args.get('data', '')
    info_dict = json.loads(student_info)
    assert type(info_dict) is dict
    response = DatabaseUtil.drop_column(g.db, info_dict)
    return response


if __name__ == "__main__":
    if len(sys.argv) != 2:
        print 'Please input the service number'
        sys.exit(1)
    try:
        global service_number
        service_number = str(sys.argv[1])
    except:
        print 'The input service number not find'
        sys.exit(1)
    global r
    r = Redis(config.get('REDIS_IP'), config.get('REDIS_PORT'))
    DatabaseUtil.setup_database(config.get(service_number + ':DATABASE_STUDENT'))
    app.run(host='0.0.0.0', port=int(config.get(service_number + ':PORT')))
Esempio n. 25
0
class GraphvizDiagramGenerator(object):
    def __init__(self, dbFile, scenario=None, outDir='.', verbose=1):
        self.dbFile = dbFile
        self.qName = os.path.splitext(os.path.basename(self.dbFile))[0]
        self.scenario = scenario
        self.outDir = outDir
        self.folder = {
            'results': 'whole_system',
            'tech': 'processes',
            'comm': 'commodities'
        }
        self.verbose = verbose
        self.colors = {}

    def connect(self):
        self.dbUtil = DatabaseUtil(self.dbFile, self.scenario)
        self.logger = open(os.path.join(self.outDir, 'graphviz.log'), 'w')
        self.setGraphicOptions(False, False)
        self.__log__('--------------------------------------')
        self.__log__('GraphvizDiagramGenerator: connected')
        if (self.scenario):
            outDir = self.qName + '_' + self.scenario + '_graphviz'
        else:
            outDir = self.qName + '_input_graphviz'

        self.outDir = os.path.join(self.outDir, outDir)
        if (not os.path.exists(self.outDir)):
            os.mkdir(self.outDir)
        #os.chdir(self.outDir)

    def close(self):
        self.dbUtil.close()
        self.__log__('GraphvizDiagramGenerator: disconnected')
        self.__log__('--------------------------------------')
        self.logger.close()
        #os.chdir('..')

    def __log__(self, msg):
        if (self.verbose == 1):
            print(msg)
        self.logger.write(msg + '\n')

    def __generateGraph__(self, dotFormat, dotArgs, outputName, outputFormat):
        dotArgs.update(self.colors)
        with open(outputName + '.dot', 'w') as f:
            f.write(dotFormat % dotArgs)
        cmd = ('dot', '-T' + outputFormat,
               '-o' + outputName + '.' + outputFormat, outputName + '.dot')
        call(cmd)

    def setGraphicOptions(self, greyFlag=None, splinevar=None):
        if (not greyFlag is None):
            self.greyFlag = greyFlag
            self.colors.update(getColorConfig(self.greyFlag))
        if (not splinevar is None):
            self.colors['splinevar'] = splinevar
        self.__log__('setGraphicOption: updated greyFlag = ' +
                     str(self.greyFlag) + ' and splinevar = ' +
                     str(self.colors['splinevar']))

    def CreateMainResultsDiagram(self, period, outputFormat='svg'):
        self.__log__('CreateMainResultsDiagram: started with period = ' +
                     str(period))

        if (not os.path.exists(
                os.path.join(self.outDir, self.folder['results']))):
            os.makedirs(os.path.join(self.outDir, self.folder['results']))

        outputName = os.path.join(self.folder['results'], 'results%s' % period)
        outputName = os.path.join(self.outDir, outputName)
        if (self.greyFlag):
            outputName += '.grey'
        if (os.path.exists(outputName + '.' + outputFormat)):
            self.__log__(
                'CreateMainResultsDiagram: graph already exists at path, returning'
            )
            return self.outDir, outputName + '.' + outputFormat

        time_exist = self.dbUtil.getTimePeridosForFlags(flags=['e'])
        time_future = self.dbUtil.getTimePeridosForFlags(flags=['f'])
        time_optimize = set(sorted(time_future)[:-1])

        tech_all = self.dbUtil.getTechnologiesForFlags(
            flags=['r', 'p', 'pb', 'ps'])

        commodity_carrier = self.dbUtil.getCommoditiesForFlags(
            flags=['d', 'p'])
        commodity_emissions = self.dbUtil.getCommoditiesForFlags(flags=['e'])

        Efficiency_Input = self.dbUtil.getCommoditiesByTechnology(
            comm_type='input')
        Efficiency_Output = self.dbUtil.getCommoditiesByTechnology(
            comm_type='output')

        V_Cap2 = self.dbUtil.getCapacityForTechAndPeriod(period=period)

        EI2 = self.dbUtil.getOutputFlowForPeriod(period=period,
                                                 comm_type='input')
        EO2 = self.dbUtil.getOutputFlowForPeriod(period=period,
                                                 comm_type='output')

        EmiO2 = self.dbUtil.getEmissionsActivityForPeriod(period=period)

        self.__log__('CreateMainResultsDiagram: database fetched successfully')

        tech_attr_fmt = 'label="%s\\nCapacity: %.2f", href="#", onclick="loadNextGraphvizGraph(\'results\', \'%s\', \'%s\')"'
        #tech_attr_fmt = 'label="%%s\\nCapacity: %%.2f", href="results_%%s_%%s.%s"'
        # tech_attr_fmt %= outputFormat
        # commodity_fmt = 'href="../commodities/rc_%%s_%%s.%s"' % outputFormat
        commodity_fmt = 'href="#", onclick="loadNextGraphvizGraph(\'results\', \'%s\', \'%s\')"'
        flow_fmt = 'label="%.2f"'

        epsilon = 0.005

        etechs, dtechs, ecarriers, xnodes = set(), set(), set(), set()
        eemissions = set()
        eflowsi, eflowso, dflows = set(), set(), set()  # edges
        usedc, usede = set(), set()  # used carriers, used emissions

        V_Cap2.index = V_Cap2.tech
        for tech in set(tech_all) - set(V_Cap2.tech):
            dtechs.add((tech, None))

        for i in range(len(V_Cap2)):
            row = V_Cap2.iloc[i]
            etechs.add((row['tech'], tech_attr_fmt %
                        (row['tech'], row['capacity'], row['tech'], period)))
            # etechs.add( (row['tech'], tech_attr_fmt % (row['tech'], row['capacity'], row['tech'], period)) )

        udflows = set()
        for i in range(len(EI2)):
            row = EI2.iloc[i]
            if (row['input_comm'] != 'ethos'):
                eflowsi.add(
                    (row['input_comm'], row['tech'], flow_fmt % row['flow']))
                ecarriers.add((row['input_comm'],
                               commodity_fmt % (row['input_comm'], period)))
                usedc.add(row['input_comm'])
            else:
                cap = V_Cap2.ix[row['tech']].capacity
                xnodes.add(
                    (row['tech'],
                     tech_attr_fmt % (row['tech'], cap, row['tech'], period)))
            udflows.add((row['input_comm'], row['tech']))

        for row in set(Efficiency_Input) - udflows:
            if row[0] != 'ethos':
                dflows.add((row[0], row[1], None))
            else:
                xnodes.add((row[1], None))

        udflows = set()
        for i in range(len(EO2)):
            row = EO2.iloc[i]
            eflowso.add(
                (row['tech'], row['output_comm'], flow_fmt % row['flow']))
            ecarriers.add((row['output_comm'],
                           commodity_fmt % (row['output_comm'], period)))
            usedc.add(row['output_comm'])
            udflows.add((row['tech'], row['output_comm']))

        for row in set(Efficiency_Output) - udflows:
            dflows.add((row[0], row[1], None))

        for i in range(len(EmiO2)):
            row = EmiO2.iloc[i]
            if (row['emis_activity'] >= epsilon):
                eflowso.add((row['tech'], row['emis_comm'],
                             flow_fmt % row['emis_activity']))
                eemissions.add((row['emis_comm'], None))
                usede.add(row['emis_comm'])

        dcarriers = set()
        demissions = set()
        for cc in commodity_carrier:
            if cc not in usedc and cc != 'ethos':
                dcarriers.add((cc, None))
        for ee in commodity_emissions:
            if ee not in usede:
                demissions.add((ee, None))

        self.__log__('CreateMainResultsDiagram: creating diagrams')
        args = dict(period=period,
                    splinevar=self.colors['splinevar'],
                    dtechs=create_text_nodes(dtechs, indent=2),
                    etechs=create_text_nodes(etechs, indent=2),
                    xnodes=create_text_nodes(xnodes, indent=2),
                    dcarriers=create_text_nodes(dcarriers, indent=2),
                    ecarriers=create_text_nodes(ecarriers, indent=2),
                    demissions=create_text_nodes(demissions, indent=2),
                    eemissions=create_text_nodes(eemissions, indent=2),
                    dflows=create_text_edges(dflows, indent=2),
                    eflowsi=create_text_edges(eflowsi, indent=3),
                    eflowso=create_text_edges(eflowso, indent=3))

        self.__generateGraph__(results_dot_fmt, args, outputName, outputFormat)
        self.__log__('CreateMainResultsDiagram: graph generated, returning')
        return self.outDir, outputName + '.' + outputFormat

    # Needs some small fixing - cases where no input but output is there. # Check sample graphs
    def CreateTechResultsDiagrams(self,
                                  period,
                                  tech,
                                  outputFormat='svg'):  # tech results
        self.__log__('CreateTechResultsDiagrams: started with period = ' +
                     str(period) + ' and tech = ' + str(tech))

        if (not os.path.exists(os.path.join(self.outDir,
                                            self.folder['tech']))):
            os.makedirs(os.path.join(self.outDir, self.folder['tech']))

        outputName = os.path.join(self.folder['tech'],
                                  'results_%s_%s' % (tech, period))
        outputName = os.path.join(self.outDir, outputName)
        if (self.greyFlag):
            outputName += '.grey'
        if (os.path.exists(outputName + '.' + outputFormat)):
            self.__log__(
                'CreateTechResultsDiagrams: graph already exists at path, returning'
            )
            return self.outDir, outputName + '.' + outputFormat

        # enode_attr_fmt = 'href="../commodities/rc_%%s_%%s.%s"' % outputFormat
        # vnode_attr_fmt = 'href="results_%%s_p%%sv%%s_segments.%s", ' % outputFormat
        # vnode_attr_fmt += 'label="%s\\nCap: %.2f"'
        enode_attr_fmt = 'href="#", onclick="loadNextGraphvizGraph(\'results\', \'%s\', \'%s\')"'
        vnode_attr_fmt = 'href="#", onclick="loadNextGraphvizGraph(\'%s\', \'%s\', \'%s\')"'
        vnode_attr_fmt += 'label="%s\\nCap: %.2f"'

        total_cap = self.dbUtil.getCapacityForTechAndPeriod(tech, period)
        flows = self.dbUtil.getCommodityWiseInputAndOutputFlow(tech, period)

        self.__log__(
            'CreateTechResultsDiagrams: database fetched successfully')

        enodes, vnodes, iedges, oedges = set(), set(), set(), set()
        for i in range(len(flows)):
            row = flows.iloc[i]
            vnode = str(row['vintage'])
            vnodes.add(
                (vnode, vnode_attr_fmt % (tech, period, row['vintage'],
                                          row['vintage'], row['capacity'])))

            if row['input_comm'] != 'ethos':
                enodes.add((row['input_comm'],
                            enode_attr_fmt % (row['input_comm'], period)))
                iedges.add((row['input_comm'], vnode,
                            'label="%.2f"' % row['flow_in']))
            enodes.add((row['output_comm'],
                        enode_attr_fmt % (row['output_comm'], period)))
            oedges.add(
                (vnode, row['output_comm'], 'label="%.2f"' % row['flow_out']))

        #cluster_vintage_url = "results%s.%s" % (period, outputFormat)
        cluster_vintage_url = "#"

        if vnodes:
            self.__log__("CreateTechResultsDiagrams: creating diagrams")
            args = dict(cluster_vintage_url=cluster_vintage_url,
                        total_cap=total_cap,
                        inp_technology=tech,
                        period=period,
                        vnodes=create_text_nodes(vnodes, indent=2),
                        enodes=create_text_nodes(enodes, indent=2),
                        iedges=create_text_edges(iedges, indent=2),
                        oedges=create_text_edges(oedges, indent=2))
            self.__generateGraph__(tech_results_dot_fmt, args, outputName,
                                   outputFormat)
        else:
            self.__log__("CreateTechResultsDiagrams: nothing to create")

        self.__log__('CreateTechResultsDiagrams: graph generated, returning')
        return self.outDir, outputName + '.' + outputFormat

    def CreateCommodityPartialResults(self, period, comm, outputFormat='svg'):
        self.__log__('CreateCommodityPartialResults: started with period = ' +
                     str(period) + ' and comm = ' + str(comm))

        if (not os.path.exists(os.path.join(self.outDir,
                                            self.folder['comm']))):
            os.makedirs(os.path.join(self.outDir, self.folder['comm']))

        outputName = os.path.join(self.folder['comm'],
                                  'rc_%s_%s' % (comm, period))
        outputName = os.path.join(self.outDir, outputName)
        if (self.greyFlag):
            outputName += '.grey'
        if (os.path.exists(outputName + '.' + outputFormat)):
            self.__log__(
                'CreateCommodityPartialResults: graph already exists at path, returning'
            )
            return self.outDir, outputName + '.' + outputFormat

        input_total = set(
            self.dbUtil.getExistingTechnologiesForCommodity(comm,
                                                            'output')['tech'])
        output_total = set(
            self.dbUtil.getExistingTechnologiesForCommodity(comm,
                                                            'input')['tech'])

        flow_in = self.dbUtil.getOutputFlowForPeriod(period, 'input', comm)
        otechs = set(flow_in['tech'])

        flow_out = self.dbUtil.getOutputFlowForPeriod(period, 'output', comm)
        itechs = set(flow_out['tech'])

        self.__log__(
            'CreateCommodityPartialResults: database fetched successfully')

        period_results_url_fmt = '../results/results%%s.%s' % outputFormat
        # node_attr_fmt = 'href="../results/results_%%s_%%s.%s"' % outputFormat
        # rc_node_fmt = 'color="%s", href="%s", shape="circle", fillcolor="%s", fontcolor="black"'

        node_attr_fmt = 'href="#", onclick="loadNextGraphvizGraph(\'results\', \'%s\', \'%s\')"'
        rc_node_fmt = 'color="%s", href="%s", shape="circle", fillcolor="%s", fontcolor="black"'

        # url = period_results_url_fmt % period
        url = '#'
        enodes, dnodes, eedges, dedges = set(), set(), set(), set()

        rcnode = ((comm, rc_node_fmt % (self.colors['commodity_color'], url,
                                        self.colors['fill_color'])), )

        for i in range(len(flow_in)):
            t = flow_in.iloc[i]['tech']
            f = flow_in.iloc[i]['flow']
            enodes.add((t, node_attr_fmt % (t, period)))
            eedges.add((comm, t, 'label="%.2f"' % f))
        for t in output_total - otechs:
            dnodes.add((t, None))
            dedges.add((comm, t, None))
        for i in range(len(flow_out)):
            t = flow_out.iloc[i]['tech']
            f = flow_out.iloc[i]['flow']
            enodes.add((t, node_attr_fmt % (t, period)))
            eedges.add((t, comm, 'label="%.2f"' % f))
        for t in input_total - itechs:
            dnodes.add((t, None))
            dedges.add((t, comm, None))

        self.__log__("CreateCommodityPartialResults: creating diagrams")
        args = dict(inp_commodity=comm,
                    period=period,
                    resource_node=create_text_nodes(rcnode),
                    used_nodes=create_text_nodes(enodes, indent=2),
                    unused_nodes=create_text_nodes(dnodes, indent=2),
                    used_edges=create_text_edges(eedges, indent=2),
                    unused_edges=create_text_edges(dedges, indent=2))
        self.__generateGraph__(commodity_dot_fmt, args, outputName,
                               outputFormat)
        self.__log__(
            "CreateCommodityPartialResults: graph generated, returning")
        return self.outDir, outputName + '.' + outputFormat

    # Function for generating the Input Graph
    def createCompleteInputGraph(self,
                                 inp_tech=None,
                                 inp_comm=None,
                                 outputFormat='svg'):
        self.__log__('createCompleteInputGraph: started with inp_tech = ' +
                     str(inp_tech) + ' and inp_comm = ' + str(inp_comm))
        outputName = self.qName
        if (not (inp_tech is None)):
            outputName += "_" + str(inp_tech)
        if (not (inp_comm is None)):
            outputName += "_" + str(inp_comm)

        outputName = os.path.join(self.outDir, outputName)
        if (self.greyFlag):
            outputName += '.grey'
        if (os.path.exists(outputName + '.' + outputFormat)):
            self.__log__(
                'createCompleteInputGraph: graph already exists at path, returning'
            )
            return self.outDir, outputName + '.' + outputFormat

        nodes, tech, ltech, to_tech, from_tech = set(), set(), set(), set(
        ), set()

        if DatabaseUtil.isDataBaseFile(self.dbFile):
            res = self.dbUtil.getCommoditiesAndTech(inp_comm, inp_tech)
        else:
            res = self.dbUtil.readFromDatFile(inp_comm, inp_tech)

        self.__log__('createCompleteInputGraph: database fetched successfully')
        # Create nodes and edges using the data frames from database
        for i in range(len(res)):
            row = res.iloc[i]
            if row['input_comm'] != 'ethos':
                nodes.add(row['input_comm'])
            else:
                ltech.add(row['tech'])
            nodes.add(row['output_comm'])
            tech.add(row['tech'])

            if row['input_comm'] != 'ethos':
                to_tech.add('"%s"' % row['input_comm'] +
                            '\t->\t"%s"' % row['tech'])
            from_tech.add('"%s"' % row['tech'] +
                          '\t->\t"%s"' % row['output_comm'])

        self.__log__("createCompleteInputGraph: creating diagrams")

        args = dict(
            enodes="".join('"%s";\n\t\t' % x for x in nodes),
            tnodes="".join('"%s";\n\t\t' % x for x in tech),
            iedges="".join('%s;\n\t\t' % x for x in to_tech),
            oedges="".join('%s;\n\t\t' % x for x in from_tech),
            snodes=";".join('"%s"' % x for x in ltech),
        )

        self.__generateGraph__(quick_run_dot_fmt, args, outputName,
                               outputFormat)
        self.__log__("createCompleteInputGraph: graph generated, returning")
        return self.outDir, outputName + '.' + outputFormat
Esempio n. 26
0
def before_request():
    g.db = DatabaseUtil.connect_db(config.get(service_number + ':DATABASE_STUDENT'))
Esempio n. 27
0
def save_analysis_data(field_name, stock_code, date, analysis):
    sql = "update pdtb_stock_tech_analysis set " + field_name + " = '" + analysis + "' where code = '" + stock_code + "' and date = '" + date + "'"
    #print sql
    dbu.update(sql)
Esempio n. 28
0
def getTechData(field, stock_code, date):
    sql = "SELECT " + field + " FROM stocktechdata WHERE STOCK_CODE ='" + stock_code + "' AND DATE ='" + date + "'"
    return dbu.query(sql)[0][0]
Esempio n. 29
0
def get_tech_data(stock_code, date, time_period=1):
    sql = 'select * from pdtb_stock_tech_data t where code =\'' + stock_code + '\' and t.date <= \'' + date + '\' order by t.date desc limit 0,' + str(
        time_period)
    return dbu.save_pd_data(sql)
Esempio n. 30
0
def callTechUpdateProc():
    dbu.call("updateStockData", ())
Esempio n. 31
0
def known_miha():
    conn = databaseUtil.create_connection("PredictedMiHA.db")
    rows = databaseUtil.get_known_miha(conn, 50, 1)
    return render_template('knownMiHA.html', data=rows)
Esempio n. 32
0
File: main.py Progetto: yujiye/wz_bs
                             charset=charset)
    except:
        #添加日志
        logging.error("unable to connect database!")
        
        
    filed = ConfigUtil.config2options("config/config_field.ini","field")
    records = getDateFromInterface()
    
    datas = []
    for record_key in records.keys():
        data = []
        r = records[record_key]
        
        data.append(str(r["messageid"]))
        data.append(str(record_key))
        if str(r["code"]) != "1":
            continue
        data.append(str(r["code"]))
        data.append(r["msg"].encode("utf-8")  )
        data.append(str(r["data"]))
#        data.append("1")
        
        datas.append(data)
        
#    DatabaseUtil.insertData(db, tableName, filed, datas)
    
    for i in datas:
        DatabaseUtil.insertAndUpdateData(db, tableName, "keyword", filed, i)
    
    db.close()