当前位置: 首页>>代码示例>>Python>>正文


Python MOSES.getDictStrings方法代码示例

本文整理汇总了Python中MOSES.getDictStrings方法的典型用法代码示例。如果您正苦于以下问题:Python MOSES.getDictStrings方法的具体用法?Python MOSES.getDictStrings怎么用?Python MOSES.getDictStrings使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在MOSES的用法示例。


在下文中一共展示了MOSES.getDictStrings方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: processDataFrame

# 需要导入模块: import MOSES [as 别名]
# 或者: from MOSES import getDictStrings [as 别名]
    def processDataFrame(self):
        start_time = datetime.datetime.now()
        total = self.data_frame.shape[0]
        self.sendMessage.emit("%d rows loaded from the file."%total)
        unfiltered_raw_data = self.data_frame
        unfiltered_raw_data.columns = MOSES.getRawDataKeys()
        raw_data = unfiltered_raw_data[[not(match) for match in list(pd.isnull(unfiltered_raw_data["WriterID"]))]]
        raw_data[["WriterID"]] = raw_data[["WriterID"]].astype(int)
        raw_data[["Editor ID"]] = raw_data[["Editor ID"]].astype(int)
        #print raw_data.columns
        rejected_data_frame = raw_data[raw_data["Overall Quality"] == "-"]
        rejected_rows = rejected_data_frame.shape[0]
        tentatively_accepted_rows = raw_data[raw_data["Overall Quality"] != "-"]
        raw_data_as_dicts = tentatively_accepted_rows.to_dict("records")
        conn = MOSES.getOINKConnector(self.user_id, self.password)
        cursor = conn.cursor()
        accepted_total = len(tentatively_accepted_rows)
        self.sendMessage.emit("%d accepted rows loaded."%accepted_total)
        progress = 0
        eta = datetime.datetime.now()
        accepted = 0
        rejected = 0
        failed = 0
        pending = total
        self.sendActivity.emit(progress, eta, accepted, rejected, failed, pending)
        primary_key_columns = ["Audit Date","Editor ID","WriterID", "FSN"]
        for each_row in raw_data_as_dicts:
            for key in each_row.keys():
                if type(each_row[key]) == unicode:
                    try:
                        each_row[key]= str(unidecode.unidecode(each_row[key])).replace('"',"'")
                    except:
                        each_row[key]= str("Failed Loading %s from the Raw Data"%key)
            success = False
            columns, values = MOSES.getDictStrings(each_row)
            sqlcmdstring = "INSERT INTO `rawdata` (%s) VALUES (%s);" % (columns, values)
            try:
                cursor.execute(sqlcmdstring)
                conn.commit()
                success = True
            except MySQLdb.IntegrityError:
                #print "Integrity Error!"
                try:
                    updation_columns = [x for x in each_row.keys() if x not in primary_key_columns]
                    update_field_list = ['`%s` = "%s"'%(column, str(each_row[column]).replace('"',"'")) for column in updation_columns]
                except:
                    print each_row
                    print sqlcmdstring
                    raise
                update_query = ", ".join(update_field_list)

                primary_key_field_list = ['`%s` = "%s"'%(column, str(each_row[column]).replace('"',"'")) for column in primary_key_columns]
                primary_key_query = " AND ".join(primary_key_field_list)
                sqlcmdstring = "UPDATE `rawdata` SET %s WHERE %s;" % (update_query, primary_key_query)
                try:
                    cursor.execute(sqlcmdstring)
                    conn.commit()
                    success = True
                except Exception, err:
                    print repr(err)
                    print sqlcmdstring
                    success = False
            except Exception, e:
                print repr(e)
                print sqlcmdstring
                success = False
开发者ID:vinay87,项目名称:oink,代码行数:68,代码来源:RawDataUploaderThread.py

示例2: int

# 需要导入模块: import MOSES [as 别名]
# 或者: from MOSES import getDictStrings [as 别名]
            counter = accepted + rejected + failed
            progress = int(math.floor(counter/total*100))
            eta = MOSES.getETA(start_time, counter, total)
            pending = total-counter
            self.sendActivity.emit(progress, eta, accepted, rejected, failed, pending)

        self.sendMessage.emit("Uploading %d rejected Audits."%rejected_rows)
        for each_row in rejected_data_frame.to_dict("records"):
            for key in each_row.keys():
                if type(each_row[key]) == unicode:
                    try:
                        each_row[key]= str(unidecode.unidecode(each_row[key])).replace('"',"'")
                    except:
                        each_row[key]= str("Failed Loading %s from the Raw Data"%key)
            success = False
            columns, values = MOSES.getDictStrings(each_row)
            sqlcmdstring = "INSERT INTO `rejected_rawdata` (%s) VALUES (%s);" % (columns, values)
            try:
                cursor.execute(sqlcmdstring)
                conn.commit()
                success = True
            except MySQLdb.IntegrityError:
                #print "Integrity Error!"
                primary_key_columns = ["Audit Date","Editor ID","WriterID", "FSN"]
                updation_columns = [x for x in each_row.keys() if x not in primary_key_columns]
                update_field_list = ['`%s` = "%s"'%(column, str(each_row[column]).replace('"',"'")) for column in updation_columns]
                update_query = ", ".join(update_field_list)

                primary_key_field_list = ['`%s` = "%s"'%(column, str(each_row[column]).replace('"',"'")) for column in primary_key_columns]
                primary_key_query = " AND ".join(primary_key_field_list)
                sqlcmdstring = "UPDATE `rejected_rawdata` SET %s WHERE %s;" % (update_query, primary_key_query)
开发者ID:vinay87,项目名称:oink,代码行数:33,代码来源:RawDataUploaderThread.py


注:本文中的MOSES.getDictStrings方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。