def start_read_service(data_directory,
                           data_store_file,
                           device_type,
                           read_frequency=15,
                           server_url=None):
        # step 1, parameters check
        status, error = FlaskHelper.parameter_check(data_directory,
                                                    data_store_file,
                                                    device_type, server_url)
        if status is False:
            print("BIB read server start failed, failed reason: %s" % error)
            return
        # step 2, start server
        reader = BibReader(data_directory)
        print("Start service reading bib device records!")
        while True:
            new_data = reader.read_new_data()
            print("\nREADING....NEW...DATA")
            print(os.linesep.join(new_data))
            print("Finished reading!\n")
            SystemHelper.append_to_file(data_store_file,
                                        os.linesep.join(new_data))

            # send data to server back-end
            send_data = {'deviceType': device_type, 'dataBatch': new_data}
            if server_url is not None and len(new_data) > 0:
                HttpHelper.post(server_url, send_data)
            time.sleep(read_frequency)
Exemple #2
0
 def swipe_current_element(self):
     SystemHelper.flush_screen()
     self.board.draw_game_board()
     time.sleep(.3)
     self.board.place_random_element()
     SystemHelper.flush_screen()
     self.board.draw_game_board()
 def generate_excel_list(home_folder):
     excel_list = []
     for sub_dir in SystemHelper.list_dirs_in_directory(home_folder, True):
         excel_list.extend(
             SystemHelper.list_files_in_directory(sub_dir,
                                                  name_suffix='.xls'))
     print("Totally collected %d excel file" % len(excel_list))
     return excel_list
Exemple #4
0
 def show_image_from_data(data):
     if os.name == 'posix':
         img = Image.open(StringIO(data))
         img.show()
     else:
         print "deprecated method for windows system!"
         tmp_file = 'tmp_%s.jpg' % DateHelper.get_current_timestamp()
         ImageHelper.save_image_file(data, tmp_file)
         ImageHelper.show_from_file(tmp_file)
         SystemHelper.delete(tmp_file)
    def _read_file_in_folder(self, date_folder):
        # step 1, get folder path, create if not exist
        processed_gz_folder = self._get_processed_gz_folder(date_folder)

        # step 2, get all gz file list
        gz_file_list = [
            f for f in SystemHelper.list_files_in_directory(date_folder)
            if f.endswith('.gz')
        ]
        print(gz_file_list)

        # step 3, read data from gz file
        for gz_file in gz_file_list:
            self.new_data.append(SystemHelper.read_gz_file(gz_file))
            SystemHelper.move_to_folder(gz_file, processed_gz_folder)
Exemple #6
0
class Game(GameLogic):

    def __init__(self, max_score, size):
        super().__init__(max_score, size)
        self.system_helper = SystemHelper()

    def swipe(self, pressed_key):
        pressed_key = self.system_helper.pressed_key(pressed_key)
        Movement.swipe(self, pressed_key)

    def game_over(self):
        for y in range(self.board.get_board_length()):
            for x in range(self.board.get_board_length()):
                if self.is_it_possible_to_swipe(x, y):
                    return False
        return True

    def reached_max_score(self):
        for y in range(self.board.get_board_length()):
            for x in range(len(self.board.get_board()[0])):
                if self.board.get_board()[y][x] == str(self.score.get_max_score()):
                    return True

    # TODO: When using arrow keys, reads multiple keystrokes at once
    @staticmethod
    def get_pressed_key():
        return ord(getch())
Exemple #7
0
def main():
    game = Game(2048, 4)
    system_helper = SystemHelper()

    game.board.place_random_element()

    print("Controls: capital/non-capital WSAD letter or arrows")
    print("To exit the game press: q")

    game.board.draw_game_board()

    while True:
        print("Your current score is: ", game.score.get_session_score())

        pressed_key = game.get_pressed_key()

        game.swipe(pressed_key)

        if game.game_over():
            print("Game over!")
            print("Restart game? (y/n)")
            time.sleep(1)
            if game.get_pressed_key() == system_helper.set_key_strokes().get("y"):
                system_helper.flush_screen()
                main()
            else:
                quit()
        elif game.reached_max_score():
            print("You WON and reached: ", game.score.get_max_score())
            print("Restart game? (y/n)")
            time.sleep(1)
            if game.get_pressed_key() == system_helper.set_key_strokes().get("y"):
                system_helper.flush_screen()
                main()
            else:
                quit()
Exemple #8
0
 def __init__(self, max_score, size):
     super().__init__(max_score, size)
     self.system_helper = SystemHelper()
 def _get_folder_by_date(self, date_str):
     return SystemHelper.join_path(self.directory, date_str)
 def _get_processed_gz_folder(self, parent_folder):
     return SystemHelper.join_path(parent_folder,
                                   self.processed_gz_folder_name)
Exemple #11
0
 def do_nothing(self):
     SystemHelper.flush_screen()
     self.board.draw_game_board()
     time.sleep(.3)
Exemple #12
0
    while True:
        print("Your current score is: ", game.score.get_session_score())

        pressed_key = game.get_pressed_key()

        game.swipe(pressed_key)

        if game.game_over():
            print("Game over!")
            print("Restart game? (y/n)")
            time.sleep(1)
            if game.get_pressed_key() == system_helper.set_key_strokes().get("y"):
                system_helper.flush_screen()
                main()
            else:
                quit()
        elif game.reached_max_score():
            print("You WON and reached: ", game.score.get_max_score())
            print("Restart game? (y/n)")
            time.sleep(1)
            if game.get_pressed_key() == system_helper.set_key_strokes().get("y"):
                system_helper.flush_screen()
                main()
            else:
                quit()


if __name__ == '__main__':
    SystemHelper.flush_screen()
    main()