Ejemplo n.º 1
0
def statistic(ketqua_n_days, days):
    distance_days = []
    for i in range(100):
        i = str(i) if i > 9 else '0' + str(i)
        distance_days.append([i, []])

    for lo in distance_days:
        lo[1] += [0]
        i = 0
        for kq in ketqua_n_days:
            if lo[0] in kq:
                lo[1] += [0]
                i += 1
            lo[1][i] += 1

    lokhan = [[lo[0], lo[1][0]] for lo in distance_days]
    coefficient = [get_coefficient(lo[1], days) for lo in distance_days]
    coefficient = scale.standard_competition_ranking(coefficient)

    lokhan = sorted(lokhan, key=lambda item: -item[1])[:10]

    most_appears = []
    ketqua_n_days = ','.join(ketqua_n_days)
    ketqua_n_days = ketqua_n_days.replace('|', ',')
    ketqua_n_days = ketqua_n_days.split(',')
    frequency = Counter(ketqua_n_days)

    for i in range(100):
        i = str(i) if i > 9 else '0' + str(i)
        if not frequency.get(i):
            frequency[i] = 0

    for k, v in frequency.iteritems():
        most_appears.append((k, v))

    most_appears = sorted(most_appears, key=lambda item: item[0])

    for i in range(len(most_appears)):
        most_appears[i] = list(most_appears[i])
        most_appears[i].append(coefficient[i])

    prefix = [0] * 10
    suffix = [0] * 10

    for k in ketqua_n_days:
        prefix[int(k[0])] += 1
        suffix[int(k[1])] += 1

    return lokhan, most_appears, prefix, suffix
Ejemplo n.º 2
0
def statistic(ketqua_n_days, days):
    distance_days = []
    for i in range(100):
        i = str(i) if i > 9 else '0' + str(i)
        distance_days.append([i, []])

    for lo in distance_days:
        lo[1] += [0]
        i = 0
        for kq in ketqua_n_days:
            if lo[0] in kq:
                lo[1] += [0]
                i += 1
            lo[1][i] += 1

    lokhan = [[lo[0], lo[1][0]] for lo in distance_days]
    coefficient = [get_coefficient(lo[1], days) for lo in distance_days]
    coefficient = scale.standard_competition_ranking(coefficient)

    lokhan = sorted(lokhan, key=lambda item:-item[1])[:10]

    most_appears = []
    ketqua_n_days = ','.join(ketqua_n_days)
    ketqua_n_days = ketqua_n_days.replace('|', ',')
    ketqua_n_days = ketqua_n_days.split(',')
    frequency = Counter(ketqua_n_days)

    for i in range(100):
        i = str(i) if i > 9 else '0' + str(i)
        if not frequency.get(i):
            frequency[i] = 0

    for k, v in frequency.iteritems():
        most_appears.append((k, v))

    most_appears = sorted(most_appears, key=lambda item:item[0])

    for i in range(len(most_appears)):
        most_appears[i] = list(most_appears[i])
        most_appears[i].append(coefficient[i])

    prefix = [0] * 10
    suffix = [0] * 10

    for k in ketqua_n_days:
        prefix[int(k[0])] += 1
        suffix[int(k[1])] += 1

    return lokhan, most_appears, prefix, suffix
Ejemplo n.º 3
0
    def evaluation(self):
        print 'Gen: %s, max: %s steps' % (self.gen, max(self.step_record))

        rank_step_record = scale.standard_competition_ranking(self.step_record)
        max_rank = max(rank_step_record)
        for i in range(len(rank_step_record)):
            if rank_step_record[i] == max_rank:
                rank_step_record[i] *= 2

        self.gen += 1

        fitness = [0] * len(self.chromosome_weight)
        sum_steps = sum(rank_step_record)
        for i in range(len(self.chromosome_weight)):
            fitness[i] = float(rank_step_record[i]) / sum_steps

        self.probability = [0] * len(self.chromosome_weight)

        self.probability[0] = fitness[0]
        for i in range(1, len(fitness)):
            self.probability[i] = self.probability[i - 1] + fitness[i]
Ejemplo n.º 4
0
    def evaluation(self):
        print "Gen: %s, max: %s steps" % (self.gen, max(self.step_record))

        rank_step_record = scale.standard_competition_ranking(self.step_record)
        max_rank = max(rank_step_record)
        for i in range(len(rank_step_record)):
            if rank_step_record[i] == max_rank:
                rank_step_record[i] *= 2

        self.gen += 1

        fitness = [0] * len(self.chromosome_weight)
        sum_steps = sum(rank_step_record)
        for i in range(len(self.chromosome_weight)):
            fitness[i] = float(rank_step_record[i]) / sum_steps

        self.probability = [0] * len(self.chromosome_weight)

        self.probability[0] = fitness[0]
        for i in range(1, len(fitness)):
            self.probability[i] = self.probability[i - 1] + fitness[i]