def get(self):

        from_year_string = self.request.get('from_year')
        to_year_string = self.request.get('to_year')

        if from_year_string:
            if from_year_string.isdigit():
                from_year = string.atoi(from_year_string)
            else:
                from_year = DEFAULT_FROM_YEAR
        else:
            from_year = DEFAULT_FROM_YEAR

        if to_year_string:
            if to_year_string.isdigit():
                to_year = string.atoi(self.request.get('to_year'))
            else:
                to_year = DEFAULT_TO_YEAR
        else:
            to_year = DEFAULT_TO_YEAR

        admin_user = users.get_current_user()

        if admin_user:
            url = users.create_logout_url(self.request.uri)
            url_linktext = 'Logout'
        else:
            url = users.create_login_url(self.request.uri)
            url_linktext = 'Login'

        db_item_query = LuckyBallItem.query(
            ancestor=TABLE_LUCKY_HISTORY).order(-LuckyBallItem.id)

        all_db_item = db_item_query.fetch(30)

        template_values = {
            'url': url,
            'url_linktext': url_linktext,
            'admin_user': admin_user,
            'from_year': from_year,
            'to_year': to_year,
            'all_db_item': all_db_item,
        }

        template = JINJA_ENVIRONMENT.get_template('templates/admin.html')
        self.response.write(template.render(template_values))
    def get(self):

        year_string = self.request.get('year')

        if year_string:
            if year_string.isdigit():
                year = string.atoi(year_string)
            else:
                year = DEFAULT_YEAR
        else:
            year = DEFAULT_YEAR

        admin_user = users.get_current_user()

        if admin_user:
            url = users.create_logout_url(self.request.uri)
            url_linktext = 'Logout'
        else:
            url = users.create_login_url(self.request.uri)
            url_linktext = 'Login'

        start_year = year * 1000
        end_year = (year + 1) * 1000

        db_item_query = LuckyBallItem.query(LuckyBallItem.id >= start_year,
                                            LuckyBallItem.id < end_year,
                                            ancestor=TABLE_LUCKY_HISTORY).order(-LuckyBallItem.id)

        all_db_item = db_item_query.fetch()

        template_values = {
            'url': url,
            'url_linktext': url_linktext,
            'admin_user': admin_user,
            'year': year,
            'all_db_item': all_db_item,
        }

        template = JINJA_ENVIRONMENT.get_template('templates/query.html')
        self.response.write(template.render(template_values))
Exemple #3
0
    def get(self):

        #
        red_missing_array = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
        blue_missing_array = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]

        #
        red_longest_missing = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
        blue_longest_missing = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]

        #
        red_select_array = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
        blue_select_array = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]

        #
        red_longest_select = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
        blue_longest_select = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]

        red_total_select = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
        blue_total_select = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]

        db_item_query = LuckyBallItem.query(ancestor=TABLE_LUCKY_HISTORY).order(LuckyBallItem.id)
        all_db_item = db_item_query.fetch()

        for item in all_db_item:

            red_list = [item.red1, item.red2, item.red3, item.red4, item.red5, item.red6]

            for i in range(1, 34):
                if i not in red_list:
                    red_missing_array[i] += 1

                    if red_select_array[i] > red_longest_select[i]:
                        red_longest_select[i] = red_select_array[i]

                    red_select_array[i] = 0

                else:
                    red_total_select[i] += 1

                    red_select_array[i] += 1

                    if red_missing_array[i] > red_longest_missing[i]:
                        red_longest_missing[i] = red_missing_array[i]

                    red_missing_array[i] = 0

            for i in range(1, 17):
                if i == item.blue:
                    blue_total_select[i] += 1

                    blue_select_array[i] += 1

                    if blue_missing_array[i] > blue_longest_missing[i]:
                        blue_longest_missing[i] = blue_missing_array[i]

                    blue_missing_array[i] = 0
                else:
                    blue_missing_array[i] += 1

                    if blue_select_array[i] > blue_longest_select[i]:
                        blue_longest_select[i] = blue_select_array[i]

                    blue_select_array[i] = 0

        red_statistics_list = []
        blue_statistics_list = []

        for i in range(1, 34):

            value = 0

            if red_longest_missing[i] - red_missing_array[i] <= 0:
                value = 0
            elif  red_longest_select[i] - red_select_array[i] == 0:
                value = 10000
            else:
                value = red_total_select[i] - red_missing_array[i] + red_select_array[i]

            red_statistics_list.append([i, red_longest_missing[i], red_missing_array[i], red_longest_select[i],
                                        red_select_array[i], red_total_select[i], value])

        red_statistics_list.sort(key=lambda x: x[6])

        for i in range(1, 17):

            value = 0

            if blue_longest_missing[i] - blue_missing_array[i] <= 0:
                value = 0
            elif blue_longest_select[i] - blue_select_array[i] == 0:
                value = 10000
            else:
                value = blue_total_select[i] - blue_missing_array[i] + blue_select_array[i]

            blue_statistics_list.append([i, blue_longest_missing[i], blue_missing_array[i], blue_longest_select[i],
                                         blue_select_array[i], blue_total_select[i], value])

        blue_statistics_list.sort(key=lambda x: x[6])

        template_values = {
            'red_statistics_list': red_statistics_list,
            'blue_statistics_list': blue_statistics_list,
        }

        template = JINJA_ENVIRONMENT.get_template('templates/index.html')
        self.response.write(template.render(template_values))
    def handle_endtag(self, tag):
        if tag == 'tbody':
            self.in_tbody = False
        elif self.in_tbody:
            if tag == 'tr':
                self.in_tr = False
                self.td_count = 0

                db_item_query = LuckyBallItem.query(LuckyBallItem.id == self.item[1],
                                                    ancestor=TABLE_LUCKY_HISTORY)
                db_item = db_item_query.fetch()

                ##database operation
                if len(db_item) <= 0:
                    selected_item = LuckyBallItem(parent=TABLE_LUCKY_HISTORY)
                    selected_item.date = self.item[0]
                    selected_item.id = self.item[1]
                    selected_item.red1 = self.item[2]
                    selected_item.red2 = self.item[3]
                    selected_item.red3 = self.item[4]
                    selected_item.red4 = self.item[5]
                    selected_item.red5 = self.item[6]
                    selected_item.red6 = self.item[7]
                    selected_item.blue = self.item[8]
                    selected_item.put()

                self.item = []

            elif tag == 'td':
                self.in_td = False
            elif tag == 'a':
                self.in_a = False
            elif tag == 'span':
                self.in_span = False