Exemplo n.º 1
0
def mainLD(cursor, conn):
    try:
        logging = getLog()
        logging.info("start mainLD.")
        start = time.clock()
        # 从数据库中取出数据
        qws_data = selectData(cursor)
        org = selectOrganization(cursor)
        if (qws_data is not None) & (org is not None):
            if (len(qws_data) != 0) & (len(org) != 0):
                # 构建特征工程,得到区,委,市未来6个月的预测结果
                pred = project_function(qws_data, org)
                if pred is not None:
                    today = datetime.datetime.now().strftime(
                        '%Y-%m-%d %H:%M:%S')  # 当前日期
                    # 将得到的结果插入数据库中
                    insert_function(cursor, conn, pred, today)
                    logging.info("未来六个月的信访分布预测存储完毕.")
            else:
                logging.warning("mainLD:\t Data is empty.")
        else:
            logging.warning("mainLD:\t select error.")
        end = time.clock()  # 运行结束时间
        logging.info("The program runs successfully. takes time:%0.2fs" %
                     (end - start))
        print(u'\n未来六个月的信访分布预测存储完毕,用时:%0.2f秒' % (end - start))  # 打印运行总时间
    except Exception as e:
        logging.error("The program runs fail. %s\t" % (e))
Exemplo n.º 2
0
# 引入 word2vec
import sys
import pandas as pd
import shortuuid
import datetime
import time
import logging
import os
from commonUtil import getLog  # 从文件路径为connectionDB2的文件中导入所有的函数
from commonUtil import getConf
from commonUtil import getConfInt
reload(sys)
sys.setdefaultencoding("utf-8")

# 获取日志对象
logging = getLog()
'''
获取某一区的所有历史数据
'''


def getDfByQuIssueCode(cursor):
    try:
        sql = "select i.Region_Code,i.Region_Name,i.Issue_Type_Code,i.Issue_Type_Name,i.Key_Word_Content,i.ISSUE_CONTENT_NUM_FLAG, c.Issue_Content cic ,i.Issue_Content  iic from PETITION_ISSUE_INFO i , Issue_Content_Info c where c.Petition_Issue_Info_Oid = i.OID"
        # sql = "select ISSUE_CONTENT from PETITION_ISSUE_INFO "
        cursor.execute(sql)
        rows = cursor.fetchmany(10)
        # rows = cursor.fetchall()
        if rows != []:
            petition_df = pd.DataFrame(rows)
            return petition_df