Example #1
0
    def makeRow(self, er, dsum, nsum, uesum, sollstunden, exrownr):
        er[Arbeitsstunden] = utils.hhmm2td(dsum)
        ueberstunden = "00:00"
        if dsum == "00:00" and nsum == "00:00" and uesum == "00:00":
            # nicht möglich
            sollstunden = "00:00"
        elif dsum == "00:00" and nsum == "00:00" and uesum != "00:00":
            ueberstunden = "-" + sollstunden
        elif dsum == "00:00" and nsum != "00:00" and uesum == "00:00":
            sollstunden = "00:00"
        elif dsum == "00:00" and nsum != "00:00" and uesum != "00:00":
            ueberstunden = "-" + uesum
            sollstunden = utils.tsub(sollstunden, nsum)
        elif dsum != "00:00" and nsum == "00:00" and uesum == "00:00":
            ueberstunden = utils.tsub(dsum, sollstunden)
        elif dsum != "00:00" and nsum == "00:00" and uesum != "00:00":
            ueberstunden = utils.tsub(dsum, sollstunden)
        elif dsum != "00:00" and nsum != "00:00" and uesum == "00:00":
            sollstunden = utils.tsub(sollstunden, nsum)
        elif dsum != "00:00" and nsum != "00:00" and uesum != "00:00":
            sollstunden = utils.tsub(sollstunden, nsum)
            ueberstunden = utils.tsub(dsum, sollstunden)

        er[Ueberstunden] = utils.hhmm2td(ueberstunden)
        er[Sollstunden] = utils.hhmm2td(sollstunden)
        self.kumArb = utils.tadd(self.kumArb, dsum)
        self.kumSoll = utils.tadd(self.kumSoll, sollstunden)
        self.kumUeber = utils.tadd(self.kumUeber, ueberstunden)
        er[Kumuliert] = utils.hhmm2td(self.kumUeber)
        er[KumFormel] = "=S" + str(exrownr + 1) + "+U" + str(exrownr)
Example #2
0
 def adjacent(self, pos):
     """
     Returns all neighboring free positions to given.
     """
     neighbors = []
     directions = NDIRECTIONS
     if pos in self.strong:
         directions = NDIRECTIONS + DDIRECTIONS
     for d in directions:
         newpos = utils.tadd(pos, d)
         if self.valid(newpos) and self.empty(newpos):
             neighbors.append(newpos)
     return neighbors
Example #3
0
def captured(board, pos, move):
    """ Returns a list of captured stones according to the capture type."""
    fpos, captype = move
    if captype == P:
        return []
    
    captured = []
    ox, oy = capx, capy = pos
    color = board[ox][oy]
    d = utils.tsub(fpos, pos)
    
    if captype == A:
        cpos = capx, capy = utils.tadd(fpos, d)
    else:
        cpos = capx, capy = utils.tsub(pos, d)
        
    while board.valid((capx, capy)) and not board.empty((capx, capy)) and board[capx][capy] != color:
        captured.append(cpos)
        if captype == A:
            cpos = capx, capy = utils.tadd(cpos, d)
        else:
            cpos = capx, capy = utils.tsub(cpos, d)
    return captured
Example #4
0
 def update(self):
     """
     Updates ongoing move (if it exists).
     """
     if self.m:
         sx, sy, dx, dy = itertools.chain.from_iterable(self.m)
         start = self[sx][sy]
         dest = self[dx][dy]
         d = utils.tsub((dx,dy),(sx,sy)) # calculate direction
         if start.rect.topleft == dest.rect.topleft:
             # reached destination
             self[sx][sy].rect = self.original
             self[dx][dy].image = self[sx][sy].image
             self[sx][sy].image = NULL_IMG
             self.m = []
             game.moving = False
             if game.current == game.player:
                 game.move()
         else:
             # keep moving
             start.rect.topleft = utils.tadd(start.rect.topleft, utils.tflip(d))
Example #5
0
def refine(board, pos, fpositions, chain = []):
    """ 
    Returns the refined future positions for given stone,
    by applying game constraints.
    Also appends the move type to each possible position.
    
    *The f in fpos, fpositions stands for "future".
    """
    if chain:
        chain = [v[0] for v in chain]
    refined = []
    for fpos in fpositions:
        x, y = pos # old position
        d = utils.tsub(fpos, pos) #direction
        
        # check for validity when chaining:
        #    - have we already visited the future position?
        #    - is the direction the same as before?
        # for more info on this look up the fanorona rules.
        if chain:
            if fpos in chain or d == utils.tsub(pos, chain[-1]):
                continue
            
        # approach
        ax, ay = utils.tadd(fpos, d)
        if board.valid((ax, ay)) and not board.empty((ax, ay)) and board[ax][ay] != board[x][y]:
            refined.append((fpos, A))
        
        # withdraw
        wx, wy = utils.tsub(pos, d)
        if board.valid((wx, wy)) and not board.empty((wx, wy)) and board[wx][wy] != board[x][y]:
            refined.append((fpos, W))
    
    # if no capturing moves found and not chaining, return paikas.
    if not refined and not chain:
        for fpos in fpositions:
            refined.append((fpos, P))
        
    return refined
Example #6
0
    def writeExcel(self, rows):
        if self.wb is None:
            wb = openpyxl.Workbook()
            wb.epoch = CALENDAR_MAC_1904  # this enables negative timedeltas
            ws = wb.active
            ws.title = self.month
        else:
            wb = self.wb
            sheetnames = self.wb.get_sheet_names()
            index = sheetnames.index(self.ws.title)
            x = self.ws.title.find("_korr")
            if x > 0:
                nr = self.ws.title[x + 5:]
                nr = 2 if nr == "" else int(nr) + 1
                title = self.ws.title[0:x] + "_korr" + str(nr)
            else:
                title = self.ws.title + "_korr"
            ws = wb.create_sheet(title, index + 1)
        ws.append([
            "Tag", "1.Einsatzstelle", "Beginn", "Ende", "KH", "Fahrt", "MVV",
            "2.Einsatzstelle", "Beginn", "Ende", "KH", "Fahrt",
            "3.Einsatzstelle", "Beginn", "Ende", "KH", "Arbeitsstunden",
            "Sollstunden", "Überstunden", "Kumuliert", "KumFormel"
        ])
        ws.append([
            "", "Übertrag", "", "", "", "", "", "", "", "", "", "", "", "", "",
            "", "", "", 0, "=S2", "=S2"
        ])
        exrownr = 2
        ctag = ""
        er = None
        sumh = {}
        sumd = {"Fahrtzeit": 0}
        dsum = "00:00"
        nsum = "00:00"
        fsum = "00:00"
        uesum = "00:00"
        sollStunden = "00:00"
        mvvSumme = Decimal("0.00")
        rows.append(("99", ))
        for row in rows:
            tag = row[R_Tag]
            if tag != ctag:
                if ctag != "":
                    self.makeRow(er, dsum, nsum, uesum, sollStunden, exrownr)
                    ws.append(er)
                    exrownr += 1
                    mr = ws.max_row
                    for col in [
                            Arbeitsstunden, Sollstunden, Ueberstunden,
                            Kumuliert, KumFormel
                    ]:
                        ws.cell(row=mr,
                                column=col + 1).number_format = hourFormat
                    ws.cell(row=mr,
                            column=MVVEuro + 1).number_format = euroFormat
                if tag == "99":
                    break
                er = ["" for _ in range(Sentinel)]
                wday = utils.day2WT(tag)
                sollStunden = self.app.menu.wtag2Stunden[utils.wday2No[wday]]
                er[Tag] = wday + ", " + tag
                ctag = tag
                dsum = "00:00"
                nsum = "00:00"
                uesum = "00:00"
            fnr = row[R_Fnr]
            es = row[R_Einsatzstelle]
            beginn = row[R_Beginn]
            ende = row[R_Ende]
            kh = row[R_Kh]
            if fnr == 1:
                er[Einsatzstelle1] = es
                er[Beginn1] = beginn
                er[Ende1] = ende
                er[Kh1] = "Ja" if kh else ""
                if row[R_Fahrtzeit] != "":
                    er[Fahrt1] = float(row[R_Fahrtzeit].replace(",", "."))
                    fsum = utils.tadd(fsum, "00:30")
                    dsum = utils.tadd(dsum, "00:30")
                    utils.dadd(sumd, "Fahrtzeit")
                if row[R_Mvv_euro] != "":
                    er[MVVEuro] = float(row[R_Mvv_euro].replace(",", "."))
            elif fnr == 2:
                er[Einsatzstelle2] = es
                er[Beginn2] = beginn
                er[Ende2] = ende
                er[Kh2] = "Ja" if kh else ""
                if row[R_Fahrtzeit] != "":
                    er[Fahrt2] = float(row[R_Fahrtzeit].replace(",", "."))
                    fsum = utils.tadd(fsum, "00:30")
                    dsum = utils.tadd(dsum, "00:30")
                    utils.dadd(sumd, "Fahrtzeit")
            elif fnr == 3:
                er[Einsatzstelle3] = es
                er[Beginn3] = beginn
                er[Ende3] = ende
                er[Kh3] = "Ja" if kh else ""
            else:
                raise ValueError("Tag " + tag + " hat fnr " + fnr)
            utils.hadd(sumh, row)
            utils.dadd(sumd, es)
            dauer = utils.tsubPause(ende, beginn)
            if es.lower() == "üst-abbau":
                uesum = utils.tadd(uesum, dauer)
            elif es.lower() in utils.nichtArb:
                nsum = utils.tadd(nsum, dauer)
            else:
                dsum = utils.tadd(dsum, dauer)
            if row[R_Mvv_euro] != "":
                mvvSumme = mvvSumme + Decimal(row[R_Mvv_euro].replace(
                    ",", "."))

        mr = ws.max_row
        mrs = str(mr)
        ws.append([])
        ws.append([
            "Formeln:", "", "", "", "", "", "=SUM(G2:G" + mrs + ")", "", "",
            "", "", "", "", "", "", "", "=SUM(Q2:Q" + mrs + ")",
            "=SUM(R2:R" + mrs + ")", "=SUM(S2:S" + mrs + ")"
        ])
        mr = ws.max_row
        for col in [Arbeitsstunden, Sollstunden, Ueberstunden, Kumuliert]:
            ws.cell(row=mr, column=col + 1).number_format = hourFormat
        ws.cell(row=mr, column=MVVEuro + 1).number_format = euroFormat

        # mvvSumme = utils.moneyfmt(mvvSumme, sep='.', dp=',')
        mvvSumme = utils.moneyfmt(mvvSumme, sep='', dp='.')
        mvvSumme = float(mvvSumme)
        ws.append([
            "Summen:", "", "", "", "", "", mvvSumme, "", "", "", "", "", "",
            "", "", "",
            utils.hhmm2td(self.kumArb),
            utils.hhmm2td(self.kumSoll),
            utils.hhmm2td(self.kumUeber)
        ])
        mr = ws.max_row
        for col in [Arbeitsstunden, Sollstunden, Ueberstunden, Kumuliert]:
            ws.cell(row=mr, column=col + 1).number_format = hourFormat
        ws.cell(row=mr, column=MVVEuro + 1).number_format = euroFormat

        ws.append([])
        ws.append(["", "Einsatzstelle", "Tage", "Stunden"])
        sumh["Fahrtzeit"] = fsum
        tsum = "00:00"
        for es in sorted(sumh.keys()):
            if es == "Üst-Abbau":
                continue
            ws.append(("", es, sumd[es], utils.hhmm2td(sumh[es])))
            mr = ws.max_row
            ws.cell(row=mr, column=4).number_format = hourFormat
            if es.lower() not in utils.nichtArb:
                tsum = utils.tadd(tsum, sumh[es])
        ws.append([])
        ws.append(("", "Arbeitsstunden", utils.hhmm2td(tsum)))
        mr = ws.max_row
        ws.cell(row=mr, column=3).number_format = hourFormat
        ws.append(("", "Sollstunden", utils.hhmm2td(self.kumSoll)))
        mr = ws.max_row
        ws.cell(row=mr, column=3).number_format = hourFormat
        ws.append(("", "Überstunden", utils.hhmm2td(self.kumUeber)))
        mr = ws.max_row
        ws.cell(row=mr, column=3).number_format = hourFormat

        # https://bitbucket.org/openpyxl/openpyxl/issues/425/auto_size-not-working
        # for c in range(Sentinel):
        #     dim = ws.column_dimensions[chr(ord("A") + c)]
        #     dim.bestFit = True
        #     dim.customWidth = False
        col_widths = {
            Tag: 12,
            Einsatzstelle1: 20,
            Beginn1: 7,
            Ende1: 7,
            Kh1: 3,
            Fahrt1: 5,
            MVVEuro: 8,
            Einsatzstelle2: 20,
            Beginn2: 7,
            Ende2: 7,
            Kh2: 3,
            Fahrt2: 5,
            Einsatzstelle3: 20,
            Beginn3: 7,
            Ende3: 7,
            Kh3: 3,
            Arbeitsstunden: 7,
            Sollstunden: 7,
            Ueberstunden: 7,
            Kumuliert: 7,
            KumFormel: 7
        }
        for k in col_widths.keys():
            ws.column_dimensions[chr(ord("A") + k)].width = col_widths[k]

        if self.path is None:
            fn = self.dataDir + "/arbeitsblatt." + self.month + "_" + self.app.menu.ids.vorname.text + "_" + \
                 self.app.menu.ids.nachname.text + ".xlsx"
            wb.save(fn)
            return (fn, ws.title)
        else:
            wb.save(self.path)
            return (self.path, ws.title)