Beispiel #1
0
def main(LAST, HASHTAG, HASHTAG_POS, SWITCH_POS_SHEETS):
    [DATE, LAST_LOCAL, HASHTAG_POS_LOCAL,
     HASHTAG_LOCAL] = LocalProperties.Reader()
    LocalProperties.Editor(
        DATE, LAST, HASHTAG_POS,
        HASHTAG)  #sets local properties file to sheets values
    choice = input("Wanna run the additional script? [Y] OR [N]: ")
    if choice == "N" or choice == "n" or choice == "ν" or choice == "Ν":
        Logs.print2("Cool")
    elif choice == "Y" or choice == "y" or choice == "υ" or choice == "Υ":
        Logs.print2("Cool Cool")
        p = subprocess.Popen([script])  #RUNS ADMIN EDIT SCRIPT
    Logs.print2("Starting main program...")
    Sheet.MainProgramCall()  #starts program and sets sheets to ON
    Logs.print2("Seems like the program has been terminated")
    Logs.print2(
        "Setting global values to Google sheets and adding log entries")
    [DATE, LAST_LOCAL, HASHTAG_LOCAL,
     HASHTAG_POS_LOCAL] = LocalProperties.OrderCorrector(
     )  #reads changed local properties AND corrects case
    #VALUE CORRECTION
    LAST_LOCAL = LAST_LOCAL.replace("LAST=", "")
    LAST_LOCAL = LAST_LOCAL.replace("/n", "")
    WORK_DONE = int(HASHTAG_LOCAL) - int(LAST)
    #VALUE CORRECTION
    [user_name,
     unique_hw_id] = Logs.UniqueIdentifier()  #gets unique ids to local vars
    Sheet.DataLogger(user_name, unique_hw_id, WORK_DONE)  #logs them
    Sheet.DataEditor(LAST_LOCAL, HASHTAG_POS_LOCAL,
                     HASHTAG_LOCAL)  #sets values to sheets
    try:
        Sheet.Exit(p)
    except:
        print("Could terminate script or it wasn't initiated")
Beispiel #2
0
def flush_scores():
    '''
    Sends the most recent match score to the spreadsheet if connected to the internet
    '''
    if ALLIANCES[ALLIANCE_COLOR.BLUE] is not None:
        Sheet.write_scores(MATCH_NUMBER, ALLIANCES[ALLIANCE_COLOR.BLUE].score,
                           ALLIANCES[ALLIANCE_COLOR.GOLD].score)
    return -1
Beispiel #3
0
def flush_scores():
    '''
    Sends the most recent match score to the spreadsheet if connected to the internet
    '''
    if alliances[ALLIANCE_COLOR.BLUE] is not None:
        Sheet.write_scores(match_number, alliances[ALLIANCE_COLOR.BLUE].score,
                           alliances[ALLIANCE_COLOR.GOLD].score)
    return -1
Beispiel #4
0
def next_match_thread(match_number):
    next_match_info = Sheet.get_match(int(match_number) + 1)
    b1name = next_match_info["b1name"]
    b2name = next_match_info["b2name"]
    g1name = next_match_info["g1name"]
    g2name = next_match_info["g2name"]
    team_names_on_deck(b1name, b2name, g1name, g2name)
Beispiel #5
0
def handler():
    with open("logs", "a", encoding='utf-8') as f:
        f.write("###########################" + "\n")
    Logs.print2("Fetching Data")
    [
        LAST, HASHTAG, HASHTAG_POS, SWITCH_POS_SHEETS, Latest_Version,
        Update_Link
    ] = Sheet.DataFetcher()
    if Latest_Version > Current_Version:
        Logs.print2(
            "Seems like you are not running the latest version of this awesome program,\n current version is: "
            + str(Current_Version) + " and the latest version is: " +
            str(Latest_Version))
        choice = input("Do you wish to update? [Y] OR [N]: ")
        if choice == "N" or choice == "n" or choice == "ν" or choice == "Ν":
            sys.exit(0)
        elif choice == "Y" or choice == "y" or choice == "υ" or choice == "Υ":
            Logs.print2("Update link is: " + Update_Link)
            webbrowser.open_new(Update_Link)
    else:
        if SWITCH_POS_SHEETS == "BLOCK":
            sys.exit(0)
        elif SWITCH_POS_SHEETS == "ON":
            choice = input(
                "Program is already running somewhere,continue anyway? [Y] OR [N] (Might lead to sync coflicts): "
            )
            if choice == "N" or choice == "n" or choice == "ν" or choice == "Ν":
                sys.exit(0)
            elif choice == "Y" or choice == "y" or choice == "υ" or choice == "Υ":
                Logs.print2("Proceeding....")
                main(LAST, HASHTAG, HASHTAG_POS, SWITCH_POS_SHEETS)
        elif SWITCH_POS_SHEETS == "OFF":
            Logs.print2("Proceeding")
            main(LAST, HASHTAG, HASHTAG_POS, SWITCH_POS_SHEETS)
def addWorkBook(filepath):
    wb = xlrd.open_workbook(filepath)

    for sheet_index in range(wb.nsheets):
        sh = wb.sheet_by_index(sheet_index)
        sheet = Sheet.openSheet(sh)
        addSheet(sheet)
def saveWorkBook(filepath):
    wb = xlwt.Workbook(encoding="utf-8")
    for sheetName in sheetNameList:
        sheet = wb.add_sheet(sheetName)
        sheetObj = Sheet.Sheet(sheet, sheetJsonDict[sheetName])
        sheetObj.SaveToExcel()
    wb.save(filepath)
Beispiel #8
0
def addWorkBook(filepath):
    wb = xlrd.open_workbook(filepath)

    for sheet_index in range(wb.nsheets):
        sh = wb.sheet_by_index(sheet_index)
        sheet = Sheet.openSheet(sh)
        addSheet(sheet)
Beispiel #9
0
def update_google_sheet(option, opt_str, value, parser):
    gmail = Gmail.GamilAPI()
    match_date = gmail.get_match_date()
    sheet = Sheet.SheetAPI(match_date)
    weekly_values, report_lack_list, score_lack_list = sheet.get_weekly_values_with_gmail(
        gmail)
    sheet.update_weekly_report(weekly_values)
    sheet.update_sheet_title(match_date)
Beispiel #10
0
def get_match(args):
    '''
    Retrieves the match based on match number and sends this information to the UI
    '''
    match_num = int(args["match_num"])
    info = Sheet.get_match(match_num)
    info["match_num"] = match_num
    lcm_send(LCM_TARGETS.UI, UI_HEADER.TEAMS_INFO, info)
def addWorkBook(filepath):
    wb = xlrd.open_workbook(filepath)
    for sheet_index in range(wb.nsheets):
        try:
            sh = wb.sheet_by_index(sheet_index)
            sheet = Sheet.openSheet(sh)
            addSheet(sheet)
        except:
            import traceback
            print traceback.format_exc()
            continue
Beispiel #12
0
def send_email(option, opt_str, value, parser):
    gmail = Gmail.GamilAPI()
    sheet = Sheet.SheetAPI()
    values = sheet.values
    subject = settings.REMIND_SUBJECT
    sender = settings.SENDER_EMAIL
    message_text = settings.REMIND_TEXT
    for value in values:
        if value[1] and value[4]:
            to = ','.join([value[1], value[4]])
            message = gmail.create_message(
                sender, '[email protected],[email protected]', subject,
                message_text)
            gmail.send_message(message)
Beispiel #13
0
def make_draft(option, opt_str, value, parser):
    gmail = Gmail.GamilAPI()
    match_date = gmail.get_match_date()
    sheet = Sheet.SheetAPI()
    weekly_values, report_lack_list, score_lack_list = sheet.get_weekly_values_with_gmail(
        gmail)
    sheet.update_weekly_report(weekly_values)
    sheet_title = sheet.update_sheet_title(match_date)
    sheet_title.extend(weekly_values)
    html = sheet.make_table_html(sheet_title)
    message_text = sheet.make_message_text(report_lack_list, score_lack_list,
                                           html)
    subject = settings.RESULT_SUBJECT
    sender = settings.SENDER_EMAIL
    to = settings.RESULT_EMAIL
    message = gmail.create_message(sender, to, subject, message_text)
    gmail.create_draft(message)
Beispiel #14
0
def openSheet(sh):
    return Sheet(sh)
Beispiel #15
0
    tk_root.protocol('WM_DELETE_WINDOW', exit_app)  # root is your root window


def exit_app():
    # check if saving
    # if not:
    tk_root.destroy()


if __name__ == "__main__":
    tk_root = Tk()
    tk_canvas = Canvas(tk_root)

    img = ImageTk.PhotoImage(file=DIR + '/icons/mindmap.png')
    tk_root.tk.call('wm', 'iconphoto', tk_root._w, img)

    graphicsInit()

    fileName = DIR + "/Sheets/tmp_thought.json"
    if len(sys.argv) >= 2:
        fileName = sys.argv[1]
    print "fileName:", fileName

    sheet = Sheet(root=tk_root, canvas=tk_canvas, fileName=fileName)

    # have to do this after creating sheet, since resizeLayout calls sheet resize functions
    tk_root.bind("<Configure>", resizeLayout)

    resizeLayout()

    tk_root.mainloop()
Beispiel #16
0
 def dict2sheet(self, data):
     sheet = Sheet("", nrmonths=72, headers=[])
     sheet.dict2obj(data)
     return sheet
Beispiel #17
0
 def new(self, name, nrcols=72, headers=[], category=None):
     sheet = Sheet(name, nrcols=nrcols, headers=headers)
     self.add(sheet, category)
     return sheet
Beispiel #18
0
from Sheet import *
from Conversions import *
import numpy as np
import matplotlib.pyplot as plt




sheet1 = Sheet(5, 4)


# TEST values and references (also done in question1)
sheet1.modifyValue(0, 0, '7')
#print(sheet1)
sheet1.modifyValue(1, 0, '5')
#print(sheet1)
sheet1.modifyValue(0, 1, '=(3+4)*2')
#print(sheet1)
sheet1.modifyValue(0, 2, '=A1+B1')
#print(sheet1)
sheet1.modifyValue(1, 2, '=A1-B1')
#print(sheet1)
sheet1.modifyValue(2, 2, '=A1*B1')
#print(sheet1)
sheet1.modifyValue(0, 3, '=(A1+8)-(A2)')
#print(sheet1)
sheet1.modifyValue(0, 0, '1')
print(sheet1)

# TEST DEPENDENCIES
sheet2 = Sheet(10,4)
Beispiel #19
0
 def dict2sheet(self, data):
     sheet = Sheet("", nrmonths=72, headers=[])
     sheet.dict2obj(data)
     return sheet
            "y_spacing":                3/16.0,
            "box_size":                 0.2,
            "box_spacing":              0.125,
            "bool_x_offset":            1.95,
            "font_size":                0.15,
            "marker_size":              0.5,
            "divider_height":           1.0/64,
            "team_x_offset":            5.6875,
            "seven_segment_width":      0.25,
            "seven_segment_thickness":  0.0625,
            "seven_segment_offset":     0.5,
            "marker_colour":            (255, 0, 0),
            "font_color":               (100, 100, 100)
}

sheet = Sheet(config)

sheet.add_field(Divider("Autonomous"))
sheet.add_field(Numbers("Auton High", ones = 3))
sheet.add_field(Numbers("Auton Low", ones = 3, prev_line=True))
sheet.add_field(Boolean("Reached"))
sheet.add_field(BulkOptions("Auto Crossed", "1 F", ["LB", "P", "CF", "M", "R", "D", "SP", "RW", "RT"]))

sheet.add_field(Divider("Tele-Op"))
sheet.add_field(String("Tally", font_size = 0.125, height = "thin", x_offset = 1.375))
sheet.add_field(Numbers("Scored High", tally = True))
sheet.add_field(Numbers("Scored Low", tally = True))
sheet.add_field(Numbers("Shots Missed", tally = True))
sheet.add_field(Divider())
sheet.add_field(BulkOptions("Crossed", "1 2 F", ["LB", "P", "CF", "M", "R", "D", "SP", "RW", "RT"]))
sheet.add_field(Image("Draw the Robot", 2, 1.5, None, prev_line = True, offset = 3.5, y_offset = 1))
Beispiel #21
0
def main():
    global falling_piece
    global shadow_piece
    global falling_sprites

    running = True

    new_piece_pending         = False
    new_piece_pending_elapsed = 0 # ms

    #
    # Text displays
    #
    level      = Level.startLevel()
    level_surf = None

    total_elapsed = 0
    zero_time     = datetime.timedelta(seconds=0)
    time_surf  = None

    points     = 0
    point_surf = None

    if display_level:
        lines = Level.lines(level)
    else:
        lines = start_lines # from Settings
    lines_surf = None

    if display_level:
        level_surf = createText(level_x, level_y, 'Level: ')
        updateText(level_surf, level)
    if display_time:
        time_surf = createText(time_x, time_y)
        updateText(time_surf, timeObj(time_limit, 0)[1])
    if display_points:
        point_surf = createText(points_x, points_y, 'Points: ')
        updateText(point_surf, points)
    if display_lines:
        lines_surf = createText(lines_x, lines_y, 'Remaining: ')
        updateText(lines_surf, lines)

    #
    # Delayed auto shift variables:
    #
    last_movement = 0 # tracks when last manual movement was
    das_triggered = False # tracks if DAS has been triggered

    #
    # The goal for hard drops is the piece to hit the bottom as fast as
    # possible. We want the user to be able to hold the hard drop button down
    # to continuously drop pieces too. BUT there needs to be a delay otherwise
    # they'll be forced to press the button for only one frame, otherwise
    # there's a good chance 2+ pieces will drop since we're running at 60 fps.
    #
    # SO, this is a delay that extends into the next piece.
    #
    hard_drop_repeat_wait         = 0
    hard_drop_repeat_wait_elapsed = 0

    #
    # Initialize invisible pieces that occupy the well. well_rows and
    # well_sheets are lists of sprite groups with one entry per row.
    #
    # well_rows: In order to detect when a row is complete we need 10 (width)
    #            surfaces per row to check when all of them are colliding with
    #            pieces on the screen.
    #
    # well_sheets: In order to move pieces down when a row is completed we
    #              need to be able to determine which blocks are *above* the
    #              row that is completed. Therefore these surfaces will stretch
    #              the width of the well and get longer and longer the farther
    #              down they are (stretching upward). These could be avoided
    #              if surfaces gave info about their position on the screen?
    #
    for y in range(0, well_length):
        # Initialize the sprites for each column
        for x in range(0, well_width):
            curr = Piece(clock, x_coord=x, y_coord=y).getSprites()
            well.add(curr)
            well_rows[y].add(curr)

        # Initialize the sheet.
        well_sheets.append(Sheet(y, well_width))

    # Initialize invisible pieces that line the outside of the well. In order:
    # top, right, bottom, left.
    border_coords  = [(x,-1)          for x in range(-1, well_width)]
    border_coords += [(well_width,y)  for y in range(-1, well_length)]
    border_coords += [(x,well_length) for x in range(well_width,  -1, -1)]
    border_coords += [(-1,y)          for y in range(well_length, -1, -1)]
    for (x,y) in border_coords:
        curr = Piece(clock, x_coord=x, y_coord=y)
        sprites = curr.getSprites()
        border.add(sprites)
        if not (y < 0 and x >= 0 and x < well_width):
            border_U.add(sprites) # shaped like a U
        if x < 0:
            border_l.add(sprites)
        if x == well_width:
            border_r.add(sprites)

    # Set up first piece
    all_drawable.add([piece.getSprites() for piece in manager.getPieces()])
    gravity = Level.gravity(level) # starts at 1 second per drop
    falling_piece = newPiece(gravity)

    saved_piece = None

    last_line_animation = lines

    # Draw countdown
    for i in range(countdown_secs, 0, -1):
        animations.append(Animation(i, clock, screen))
        while animations:
            clock.tick(fps)
            updateScreen()

    # Flush input buffer - applicable if countdown happened
    pygame.event.get()

    #
    # MAIN LOOP
    #
    while running:

        clock.tick(fps)
        total_elapsed += clock.get_time()

        if display_time:
            if time_counts_up:
                time_obj, time_string = timeObj(0, total_elapsed)
            else:
                time_obj, time_string = timeObj(time_limit, -total_elapsed)
            updateText(time_surf, time_string)
            if time_obj <= zero_time:
                updateText(time_surf, zero_time)
                print(points)
                gameOver()

        last_movement += clock.get_time()

        reverted_downward_move = False

        # See explanation in Settings.py, under MISC.
        if level_enabled:
            new_piece_pending_period = Level.nppp(level)
        else:
            new_piece_pending_period = hard_drop_wait

        if new_piece_pending:
            new_piece_pending_elapsed += clock.get_time()

        if hard_drop_repeat_wait:
            hard_drop_repeat_wait_elapsed += clock.get_time()
            if hard_drop_repeat_wait_elapsed > 200:
                hard_drop_repeat_wait = False

        #######################################################################
        #                            KEY PRESSES                              #
        #######################################################################

        events = pygame.event.get()

        # Artificially add an arrow key to the events queue. Without this code,
        # holding a key down does nothing.
        if not events:
            keys = pygame.key.get_pressed()
            for key in hard_drop_key, left_key, right_key:
                if keys[key]:
                    if last_movement > 150 or das_triggered:
                        das_triggered = True
                        events.append(pygame.event.Event(KEYDOWN, {'key': key}))

        for event in events:
            if event.type == KEYDOWN:

                key = event.key

                # Quit
                if key in quit_keys:
                    running = False

                # Store piece and restart loop.
                elif key == hold_key:
                    falling_piece, saved_piece = hold(falling_piece,
                                                      saved_piece, gravity)

                    # NOTE: not sure if these are necessary but they could save
                    # the game from a few bugs.
                    new_piece_pending = False
                    das_triggered = False
                    last_movement = 0

                    updateScreen()
                    continue

                # Code related to user moving or rotating piece
                else:
                    last_movement = 0

                    # Code for downward movement - does not affect shadow.
                    if key in down_keys:
                        if key in hard_drop_keys:
                            if hard_drop_repeat_wait:
                                continue
                            lines_down = well_length
                        else:
                            lines_down = 1

                        successful_drops = 0
                        for i in range(lines_down):
                            falling_piece.move(hard_drop_key)
                            if needToRevert(falling_piece):
                                falling_piece.move(cheat_key)

                                # Override normal detection
                                if key in hard_drop_no_wait_keys:
                                    new_piece_pending = True
                                    new_piece_pending_period = 0
                                    hard_drop_repeat_wait = True
                                    hard_drop_repeat_wait_elapsed = 0
                                break
                            successful_drops += 1

                        if display_points:
                            points += Scoring.drop_points(successful_drops)
                            updateText(point_surf, points)

                    # Other movement
                    else:
                        # Let player move piece even around the bottom
                        #new_piece_pending = False

                        falling_piece.dispatch(key)
                        shadow_moved = shadowMove(shadow_piece, key)

                        # Try wall/floor kicks if a rotation was illegal.
                        if needToRevert(falling_piece) and key in rotate_keys:
                            kick(falling_piece)

                        # Revert movement if it was illegal and can't be done.
                        # shadowMove usually takes care of reverting itself but
                        # since the dection is different we need to double
                        # check here.
                        if needToRevert(falling_piece):
                            falling_piece.dispatch(opposite[key])
                            if shadow_moved:
                                shadow_moved = shadowMove(shadow_piece,
                                                          opposite[key])
                                if not shadow_moved:
                                    print('no revert = bad?')

                        # If we just moved the piece left/right and it's now
                        # over a gap, reset the new piece pending variables.
                        #if key in left_right_keys:
                        if True:
                            falling_piece.move(hard_drop_key)
                            if not needToRevert(falling_piece):
                                new_piece_pending = False
                            falling_piece.move(cheat_key)

            elif event.type == KEYUP:
                das_triggered = False
                if event.key in hard_drop_keys:
                    hard_drop_repeat_wait = False

            elif event.type == QUIT:
                running = False

        #######################################################################
        #                           PIECE MOVEMENT                            #
        #######################################################################

        # Auto movement
        if not new_piece_pending and falling_piece.handleGravity(needToRevert):
            #reverted_downward_move = checkDownwardRevert(falling_piece)
            reverted_downward_move = True


        # If the shadow and the falling piece overlap completely, we're at the
        # bottom so let's just kill off the shadow. This is really just because
        # shadow movement is buggy and this avoids some corner cases.
        if len(groupcollide(falling_sprites, shadow_sprites)) >= \
           len(falling_piece.getSprites()):
            resetShadow()


        # The piece can't move down farther if it just collided with another
        # piece or is currently colliding with the bottom row of invisible
        # blocks.
        if not new_piece_pending and (
            reverted_downward_move or
            groupcollide(falling_sprites, well_rows[-1])
        ):
            new_piece_pending         = True
            new_piece_pending_elapsed = 0

        # Piece is locked in. Check for row completion and eventually spawn a
        # new piece.
        if new_piece_pending and \
           new_piece_pending_elapsed >= new_piece_pending_period:

            new_piece_pending = False

            # Transfer falling_sprites to piece_sprites and reset variables
            # related to the falling piece.
            piece_sprites.add(falling_sprites)
            falling_sprites = pygame.sprite.Group()
            resetShadow()

            # Check all rows for completion.
            rows_completed = 0
            for i, row_sprites in enumerate(well_rows):
                sheet = well_sheets[i] # idx 0 will be None

                # 'collisions' will be a dict of Block objects that are in
                # 'piece_sprites'.
                collisions = groupcollide(piece_sprites, row_sprites)

                # Completed row!
                if len(collisions) == well_width:
                    rows_completed += 1

                    # Delete the row
                    for block in collisions:
                        for piece in pieces:
                            if block in piece.getSprites():
                                piece.remove(block)

                        # We don't need to keep empty Piece objects around.
                        if not piece.getSprites():
                            pieces.remove(piece)

                    # Move other pieces down.
                    for piece in pieces:
                        piece.downIfCollide(sheet)

            # Check for new level or game over, depending on the mode.
            if display_lines:
                lines -= rows_completed
                updateText(lines_surf, lines)

                if lines <= 0:
                    # New level
                    if level_enabled:
                        level += 1
                        lines, new_piece_pending_period, gravity = \
                                                    Level.updateLevel(level)
                        updateText(level_surf, level)
                        updateText(lines_surf, lines)
                    # User cleared all the lines
                    else:
                        updateText(lines_surf, 0)
                        print(timeObj(0, total_elapsed)[1])
                        gameOver()

            # Handle animations
            if display_lines and not level_enabled:
                if lines <= 10 and lines != last_line_animation:
                    last_line_animation = lines
                    animations.append(Animation(lines, clock, screen))

            if display_points:
                points += Scoring.line_points(rows_completed)
                updateText(point_surf, points)

            falling_piece = newPiece(gravity)

        updateScreen()