Excelの統計運動おもちゃのプロジェクトチームエクセルデイリー

輸入xlrd 
輸入xlwtの
輸入OS、タイム
輸入JSON 
xlrd輸入xldate_as_tupleから
日時インポート日時から
の輸入ロガーtoydir.logutilから
ロガー=ロガー( "根"、rootstdout =真、handlerListは= [ 'I'が'E'、])
から# matplotlibのインポートfont_manager 
#my_font = font_manager.FontProperties(FNAME = "C:/Windows/Fonts/simsun.ttc")

クラスExcelUnit(オブジェクト):
     デフ__init __(自己、excel_path):
         self.excelObject = xlrd.open_workbook(excel_path)
         自己.sheetObject = self.excelObject.sheet_by_index(0)
         self.sheet_name = self.sheetObject.name 
         self.rows = self.sheetObject.nrows 
         self.cols = self.sheetObject。ncolsの

     DEF getSpecialCell(自己、X、Y):
         戻りself.sheetObject.cell(x、y)は.VALUE 

     DEF read_excel(自己):
         リスト= [] 
         の範囲内の行(1、self.rows):
             リスト= self.sheetObject .row_values(行):self.cols] 

             セル= self.sheetObject.cell_value(行、1)
             してみてください:
                 グローバルDを
                 D =日時(* xldate_as_tuple(セル、0))
             eと例外を除い:
                合格
             = d.strftime細胞( '%Y /%のM /%のD')
             のリスト[1] =細胞は
             list.append(タプル(リスト)) 戻りリスト

getAllExcellContent(モード)DEF。
    "" "モード= 0 - >週、モード= 1->月" "" 
    absxslFileList = [] 
    xslList = [] 
    excelDir =なし
    かのモード== 0:
        excelDir = os.getcwd()+ "\\ sourcexsldir" 
    のelifモード== 1:
        excelDir = os.getcwd()+ "\\ months_sourcexsl" 
    os.path.isdir(excelDir)場合:
        os.listdir(excelDir)中のOの場合:
            absxslfile = excelDir + '\\' + O 
            O場合。スプリット( '') - 1] == "XLSX"とos.path.isfile(absxslfile):
                absxslFileList.append(absxslfile)
    absxslFileListでXSL用:
        excelInst = ExcelUnit(XSL)
        xslList.append(excelInst。read_excel()) 
    xslList返す


デフデータセット(get_excelsを): 
    error_sum = [] 
    ニュース= [] 
    の内容= [] 
    work_attr = [「ユースケースの製造」、「試験調製物」、「実行する実施形態に機能」、「その他のテスト実行」、「バグ認証」、「試験結果仕上げ」、「その他」、「運用・保守開発」] 
    :のためにExcelでget_excels 

        Excelの行のための:
            #プリント(行)
            の行IF [0]と行の行及び[2]と行[1] [3]:
                [1]行.count( "/")== IFそして行2 [4] work_attrで:
                    #1 logger.info(行)
                    contents.append(行)
                他:

                    logger.error( "外れ値、異常なデータ・サマリー・シートを参照")
                    logger.error(「+++++ +++++++++++++++「)
                    logger.error(行)
                    error_sum。(行)を追加します
                    #raiseとValueError( "DATE形式または作業自然は、修正してくださいチェックしない!")
            それ以外:
                印刷( "======出现格式异常数据==========")
                logger.error(行)
    ユーザによって#order 
    newdt =ソート:(Xコンテンツ、キー=ラムダX [0])
    )users_set =リスト(セット([I [0] I newdtにするため])
    #USERのGROUPBY 
    :users_setにおけるUため
        per_list =リスト(フィルタ(ラムダX:X [0] == U、newdt))
        news.extend(per_list)
    new_d = [] 
    R用error_sumで:
        J =リスト(R)
        J [1]、jは[5] Jが= [ 5]、J [1] 
        K =タプル(J)
        new_d.append(k)の
    戻りニュース、users_set、new_d

デフsplitdate(モード):
    DATAS、ユーザー、ERR =データセット(getAllExcellContent(MODE =モード))
    all_dts = [] 
    ユーザーがユーザーのために:
       my_listという=リスト(フィルタ(ラムダO:O [0] ==ユーザ、DATAS))
       #プリント(my_listという)
       my_program = my_listという[0] [3] 
       my_date_list =ソート(リスト(セット([I [1] iに対するmy_listというで])))
       インデックス、列挙内の日(my_date_list)用:
           LK = [] 
           work_times = [] 
           useable_times = [] 
           casewriteNumbers = [] 
           case_excuteNum = [] 
           bug_submitNum = [] 
           bug_regNum = [] 
           my_listというにおけるDTのために:
               [1] ==日DT場合:
                   もし[4] = "其它" DT:!
                       useable_time =フロート(DT [5])[5]他0 dtの場合 
                       useable_times.append(useable_time)

                   。WH =フロート(DT [5])であればSTRストリップ([5] dt)は()他0 
                   CW = INT(DT [6])STR IF(DT [6])。ストリップ()そうでなければ0 
                   CE = INT(DT [7])であればSTR(DT [7])。ストリップ()そうでなければ0 
                   bug_sub =フロート( DT [8])他のSTR(DT [8])。ストリップ()が0であれば
                   他bug_reg =フロート(DT [9])STR IF(DT [9])。ストリップ()0 

                   casewriteNumbers.append(CW)
                   case_excuteNum。追加(CE)
                   bug_submitNum.append(INT(bug_sub))
                   bug_regNum.append(INT(bug_reg))
                   work_times.append(フロート(WH))
           work_saturation =フロート( '%3F' %(合計(useable_times)/ 7))
           lk.insert(0、ユーザ) 
        pg_list = [] 
           lk.insert(1、work_saturation)
           lk.insert(2日)
           lk.insert(3、my_program)
           lk.insert(4、和(work_times))
           lk.insert(5、和(useable_times))

           all_dts.append(タプル(LK))
    all_dtsのIため#:
    #1 logger.debug( I)
    all_dts返す

(daily_dt):DEF week_sumを

    人=リスト(セット([daily_dtにおけるjに対するJ [0]))
    allperson_week = [] 
    人のpため
        [0 O:リスト(フィルタ(ラムダO =#1 my_weekdts ] == P、daily_dt))
        weekTime = [] 
        useable_weekTime = [] 
        PROG = [] 
        男= P 
        daily_dtにおけるDTのために:
            oneday_hour =フロート(DT [4])STR(DTなら[4])。他のストリップ()0
        oneperson_oneweek = [] 
            oneday_usebaletime =フロート(DT [5])他0 STR(DT [5])ストリップ()ば
            なら[0] == P DT:
                weekTime.append(oneday_hour)
                useable_weekTime.append(oneday_usebaletime)
                pg_list。追加(DT [3])
        prog.append(pg_list)
        lenの場合(weekTime)== 5:
            week_saturation =フロート( '%3F' %(合計(useable_weekTime)/ 5/7))
        他:
            week_saturation =フロート(」 %.3f」%(合計(useable_weekTime)/ LEN(weekTime)/ 7))
        リストにおけるPGのため#(セット(PROG)):
        (0、男性)oneperson_oneweek.insert 
        oneperson_oneweek.insert(1、week_saturation) 
        oneperson_oneweek.insert(2、和(weekTime))
        allperson_week.append(タプル(oneperson_oneweek)) 
    :orderProgramWeek =は(X [1]、逆=真allperson_week、キー=ラムダX)ソート
    orderProgramWeek.insert(0、( "姓名"、 "周日人均和度"、 "周生产时长"))
    を返すorderProgramWeek 


デフsara_bypro():
    #getのinitデータはOT作業含ん
    件のデータ、ユーザー、ERR =データセット(getAllExcellContent(モード= 0)) セットプログラム
    プロ=リスト(セット([I [3] DATASにおけるI]))のために
    allpg_list = [] 
    プロにおけるPGため
        pg_user = [] 
        onepro = [] 
        useable_list = [] 
        work_time = [] 
        DATASにおけるDTのために:

           もしDT [3] == PG:
               pg_user.append( DT [0])
               one_dayhour =フロート(DT [5])であれば、DT [5]他0 
        allpg_list.append(タプル(onepro)) 
               ![4] = "其它" DTの場合:
                   useable_time = one_dayhour 
                   useable_list.append(useable_time)
               work_time.append(one_dayhour)は
        、このプロセット#USER 
        real_userを=リスト(セット(pg_user)) プログラム
        onepro.append(PG)
        #program週サラ
        onepro.append(フロート( '%。 3F」%(合計(useable_list)/ 35 / LEN(real_user))))
        #week_pro有效时长
        onepro.append(フロート( '%3F' %(合計(useable_list))))
        #weekプロworktimes 
        onepro.append(フロート( '%3F' %(合計(work_time)))) 汇总各プログラム週サラ
    allpg_list =ソート(allpg_list、キー=ラムダoneRow:oneRow [1])
    戻りallpg_list

DEF()create_sheet:
    pro_tbheader = [「プロジェクト」、「一人当たりのプロジェクトを人間彩度」、「長時間の生産」と「持続作品の」] 
    #err_tbheader = [「名前」、「長時間の作業」、「仕事の内容」、「所属実行額の実施形態でプロジェクトグループ「」自然「」日付「」書き込み量ケース「」 『]の量の検証「」バグファイラ「」バグ
    headers_summary = [』名前「」長い作品を「」仕事の内容「」チーム「」自然「」日付に属している「」書かれた例量「」「」提出されたバグは量「」バグの検証量「と実行額の実施形態] 
    XLSX = xlwt.Workbook()
    = week_sum person_saraday(splitdate(0))
    daily_list、ユーザー、ERR =データセット(getAllExcellContent(MODE = 0))
    pro_saralist = sara_bypro()
    pro_saralist.insert(0、タプル(pro_tbheader)) 
    #add errtbヘッダ
    err.insert(0、タプル(headers_summary)) 
    cur_sheet = xlsx.add_sheet( 'プロジェクト人力')
    day_sheet = xlsx.add_sheet( "日彩度「) 
    error_sheet = xlsx.add_sheet( "异常数据汇总」)
    summaryContainOt = xlsx.add_sheet( "デイリー概要")
    pro_sheet = xlsx.add_sheet( "プロジェクト・ウィーク飽和")
    mon_program = xlsx.add_sheet( "飽和月プロジェクト")
    mon_day_sheet = xlsx.add_sheet( "月刊デイ飽和")
    group_sheet_week = xlsx.add_sheet( "自由な組み合わせ")
    month_init_data = xlsx.add_sheet( "月刊生データ")
    #grep_sheet = xlsx.add_sheet( "フィルタの概要")
    #summaryContainOt = xlsx.add_sheet( "デイリー・ニュースのサマリー")
    new_d = [] 
    :のためのR&LT daily_listにおいて
        J =一覧(R&LT)
        [1] [5] [5] [1] J、J = J、J 
        、K =タプル(J)
        new_d.append(K) 
入力概要OT含まれ
    call_new_d = new_dを
    #挿入操作は
    、call_new_d.insert(0タプル(headers_summary))
    e_indexため、one_err列挙に(call_new_d):入力program_sara
            範囲内e_col(LEN(headers_summary))のために:
              summaryContainOt.write(e_index、e_col、one_err [e_col]) アクションがTBヘッダ追加
    new_s =リスト(フィルタ(ラムダX:X [4] = "其它"、new_d))
    #1 new_s.insert(0、タプル(headers_summary ))
    #input data_summary 
    e_indexため、one_err列挙で(new_s):
            範囲内e_colため(LEN(headers_summary)):
              cur_sheet.write(e_index、e_col、one_err [e_col]) 入力person_sara 
    e_indexため、one_err列挙で(person_saraday ):
            の範囲内e_col(3):
              day_sheet.write(e_index、e_col、[e_col] one_err)
    e_indexため、one_err列挙(pro_saralist)において:
            範囲内e_col(4)のための:)) 
            reload_mon_pro.extend(I [1])
              pro_sheet.write(e_index、e_col、one_err [e_col]) 入力ERRシート
    e_indexため、one_err列挙で(ERR):
            範囲内e_col(LEN(headers_summary))のために:
              one_err error_sheet.write(e_index、e_col、[e_col] )
    #get月データ
    program_month、month_daily = sum_month()
    logger.debug(program_month)
    logger.debug(month_daily)
    reload_mon_pro = [] 
    program_monthにおけるiについて:
            I [1] .insert(0、(I [0]、 '' 、 ''、 ''))
            iは[1] .insert(1、( "项目组"、 "月饱和"、 "工时"、 "有效时长"))
    (reload_mon_pro)logger.info 
    インデックスに対して、列挙内の行(reload_mon_pro):
        範囲内のCOL(4):
            mon_program.write(索引、列、行[COL])
    #input月日シート
    reload_mon_data = [] 
    iについてmonth_dailyで:
        I [1] .insert(0、(I [0]、 ''、 ''))
        reload_mon_data .extend(I [1])
    インデックスのための、行列挙で(reload_mon_data):
        範囲内のCOL(3):
            mon_day_sheet.write(索引、列、行[COL]) 入力月のinitデータ
    インデックスの、列挙に行(sum_mutiMonth()):
        範囲内COL用(10):
            month_init_data.write(索引、列、行[COL])
    #input grepの設定 
    列挙でインデックスの行(filter_config_program(MODE = 0) ):
        COLのための範囲内(2):
            group_sheet_week.write(索引、列、行[COL]) 
    logger.info(「全月份汇总。%s」は%のmonth_data)
    strf = time.strftime( "%Y%M%D_%H_%M"、time.localtime())
    xlsx.save(os.getcwd()+ "\\ result_summarydir \\要約_ {}。XLS" .format( strf))

DEF sum_month():
    daily_dt = splitdate(MODE = 1)
    month_list = [STR(I)Iの範囲内の(1,13)用] 
    excel_month =リスト(セット([STR(INT(これ[2] .split ( '/')[1]))そのためdaily_dtで]))
    intersect_month =リスト(セット(month_list).intersection(セット(excel_month)))
    logger.info( "交集月份如下:%S" %intersect_month)
    month_data = [(STR(M)+ "月份日饱和度汇总"、リスト(フィルタ(ラムダX:STR(INT(X [2] .split( '/')[1]))== M、daily_dt)) )intersect_month]におけるM用
    month_dataメタため#:
    プリント(メタ)
    month_daily = [(これ[0]、ITER(month_data)でそれのためのreduce_month(それは、[1]))]
    program_month = reduce_program_month(intersect_month)
    プリント(program_month)
    リターンprogram_month、month_daily 


DEF(daily_dt)をreduce_month:
    人=リスト(セット([daily_dtにおけるjに対するJ [0]))
    allperson_month = [] 
    者におけるpの:
        monthTime = [ ] 
        useable_monthTime = [] 
        PROG = [] 
        男= P 
        pg_list = [] 
        oneperson_onemonth = [] 
        daily_dtにおけるDTのために:
            。oneday_hour =フロート(DT [4])STR([4] DT)であればストリップ()そうでなければ0 
            oneday_usebaletime =他のフロートstrの場合([5] DT)(DT [5])。ストリップ()0  
            もし、DT [0] == P:
                monthTime.append(oneday_hour)
                useable_monthTime.append(oneday_usebaletime)
                pg_list.append(DT [3])
        prog.append(pg_list)
        mon_saturation =フロート( '%3F' %(合計(useable_monthTime)/ LEN(monthTime)/ 7))
        (0 oneperson_onemonth.insert 、男)
        (1、mon_saturation)oneperson_onemonth.insert 
        oneperson_onemonth.insert(2、和(monthTime))
        allperson_month.append(タプル(oneperson_onemonth))
    X [1]、逆= TRUE:orderMonths =(allperson_month、キー=ラムダXソート)
    orderMonths.insert(0、( "姓名"、 "月人均饱和度"、 "月生产时长"))
    戻りorderMonths  
DEF(intersect_months)をreduce_program_month。
    #は初期化データは、OT作業含ん取得
    件のデータを、ユーザー、ERR =データセット(getAllExcellContent(MODE = 1)) 
    Mons_progarm = [] 
    intersect_monthsにおけるmについて:
        mondatas =リスト(フィルタ(ラムダX:STR(INT(X [1] .split( '/')[1]))== M、DATAS))
        counter_workdate =リスト(セット([I [1] iに対するmondatasで]))
        logger.debug( "%sの月项目工作日天数:%s"は%(M、LEN(counter_workdate)))
        logger.debug(」%sの月过滤数据:%S」%(M、mondatas)) セットプログラム
        プロ=リスト)(セット([I [3] mondatasにおけるiに対する])
        allpg_list = [] プロにおけるPGため
            pg_user = [] 
            onepro = [ ] 
            useable_list = [] 
            work_time = [] 
            DATASにおけるDTのために:
                もし[3] == PG DT:
                    pg_user.append(DT [0])
                    one_dayhour =フロート(DT [5])STR(DT [5])ストリップ()それ以外の場合は0。
                    DTであれば[4] = "其它":!
                        useable_time = one_dayhour 
                        useable_list.append( useable_time)
                    work_time.append(one_dayhour)
            real_user =リスト(セット(pg_user))
            onepro.append(PG)
            onepro.append(フロート( '%3F' %(合計(useable_list)/ LEN(counter_workdate)/ 7 / LEN( real_user))))
            onepro.append(フロート( '%3F' %(合計(useable_list))))
            onepro.append(フロート( '%3F' %(合計(work_time))))
            allpg_list.append(タプル(onepro)) 
        Mon_allpg_list =ソート(allpg_list、キー=ラムダoneRow:oneRow [1])
        Mons_progarm.append((M + "月项目饱和度"、Mon_allpg_list))を
    返すMons_progarm 


DEF init_json(): 
もしos.path.exists(OS .getcwd()+」。/ configに。JSON '):パス
    他#:
    #1 DATAS = { "磨刀小分队1 ":["陈权」、 "王大伟"]、 "磨刀分队2":[ "易铭"]} 
    オープン(os.getcwd(と#)+ '/ config.json'、」 W + F 'として、エンコード= "UTF-8"):
    #json.dump(DATAS、F、ensure_ascii = Falseを、インデント= 3)
    開いた状態(os.getcwd()+ "./ config.json"、R' + E」として、エンコード= "UTF-8"):
        init_data = json.load(E)
    DATAS = [kについて(K、V)、init_data.itemsにおけるV()] 
    戻りDATAS 
DEF)(モードfilter_config_program。
    もしINT(モード)== 1:
        データ= splitdate(モード) 
    他:
        データ= splitdate(0)
    DEF iter_res():
        summarys = [] 
        GP、init_jsonにおけるユーザー()のために:
            get_coinfig_data =リスト(フィルタ(ラムダX:X [0]ユーザに、データ)) 
            #プリント(get_coinfig_data)
            = SUMのgp_sara([I [-1] Iためget_coinfig_dataで])/ LEN(リスト([get_coinfig_dataにするためのJ [2] J] SET()))/ 7 / LEN(ユーザ)
            summarys.append((GP、 gp_sara))
        リターンsummarys 
    データ= iter_res()
    data.insert(0、( "グループ名"、 "グループ飽和"))
    データを返す
DEF sum_mutiMonthを():
    ヘッダー= [ "名前"、 "日付"、「ジョブコンテンツ「「自然「」長い仕事「」書かれた例量、 『』実行量の実施例に「」バグ提出量「」バグの検証量「]」チームに属している」
    (データ、ユーザー、ERR =データセットgetAllExcellContent(1))
    data.insert(0、タプル(ヘッダ))
    データを返す

IF __name__ == '__main__':

    create_sheet()
    #1 sum_month()
    #A = filter_config_program(0) プリント( "分组结果:%S" %のA) プリント(sum_mutiMonth())

  

おすすめ

転載: www.cnblogs.com/SunshineKimi/p/11295579.html