Beispiel #1
0
    def clean(self, *args, **kwargs):
        super(InitialPeriodLimitingForm, self).clean(*args, **kwargs)

        (period_total, period_width,
         period_limit) = utils.get_config('initial_account_period_total',
                                          'initial_account_period_width',
                                          'initial_account_period_limit')

        post_count = self.get_author().post_set.count()
        if post_count < period_total:
            window_start = timezone.now() - period_width

            posts_in_window = (
                self.get_author().post_set.order_by('-created').filter(
                    created__gte=window_start).count())

            if posts_in_window >= period_limit:
                formated_width = utils.format_duration(period_width)
                message = (
                    'While you\'ve made less than %d posts, your account is '
                    'limited in creation of new posts. You can make at most '
                    '%d posts in a period of %s. You will be able to continue '
                    'to post as prior posts roll out of this window.') % (
                        period_total, period_limit, formated_width)
                raise ValidationError(message, code='FLOOD_CONTROL')
Beispiel #2
0
  def generate_summary(self, all_data):
    data = [[x[key] for x in all_data] for key in self._keys]
    averages = [0 for key in self._keys]
    for i, col in enumerate(data):
      for x in col:
        averages[i] += x
      averages[i] /= len(col)

    total_average = 0
    for average in averages:
      total_average += average

    parts = []
    for i, duration in enumerate(averages):
      class_index = i % len(DistributionColumn.CLASSES)
      part_class = DistributionColumn.CLASSES[class_index]
      percentage = 100 * duration / total_average if total_average != 0 else 0
      content = utils.format_duration(duration)
      parts.append(
        DistributionColumn.PART_HTML.format(
          cls=part_class,
          percentage=percentage,
          content=content
        )
      )
    num_parts = len(parts)
    distribution_html = ''.join(parts)
    return DistributionColumn.DISTRIBUTION_HTML.format(
      num_parts=num_parts,
      distribution=distribution_html
    )
Beispiel #3
0
  def generate_cell(self, data):
    data = [data[key] for key in self._keys]

    total = 0
    for duration in data:
      total += duration

    parts = []
    for i, duration in enumerate(data):
      class_index = i % len(DistributionColumn.CLASSES)
      part_class = DistributionColumn.CLASSES[class_index]
      percentage = 100 * duration / total if total != 0 else 0
      content = utils.format_duration(duration)
      parts.append(
        DistributionColumn.PART_HTML.format( cls=part_class,
          percentage=percentage,
          content=content
        )
      )
    num_parts = len(parts)
    distribution_html = ''.join(parts)
    return DistributionColumn.DISTRIBUTION_HTML.format(
      num_parts=num_parts,
      distribution=distribution_html
    )
Beispiel #4
0
 def generate_summary(self, all_data):
   durations = [x[self._key] for x in all_data]
   average = 0
   for duration in durations:
     average += duration
   average /= len(durations)
   return DataColumn.CELL_HTML.format(utils.format_duration(average))
Beispiel #5
0
def run():
    if config['generate_tree']:
        # drop existing database and recreate
        postgres_create_db(config['postgres_db'], DBNAME)

        connection = psycopg2.connect(config['benchmark_db'])
        tree = Tree(connection)

        with tree() as transaction:
            transaction.install()
            # create tree with test data
            generate_tree(transaction, config['levels'], config['per_level'])

    connection = psycopg2.connect(config['benchmark_db'])
    tree = Tree(connection)

    with tree() as transaction:
        postgres_analyze_db(transaction.cursor)

        # build a list of benchmarks to run
        benchmarks = create_benchmarks(transaction, config)
        benchmarks_to_run = []
        filter_benchmarks = config['filter_benchmarks']

        for b in benchmarks:
            if not filter_benchmarks or filter_benchmarks in b.name:
                benchmarks_to_run.append(b)

        print()

        if len(benchmarks_to_run):
            print("Running benchmarks..")

            for benchmark in benchmarks_to_run:
                print(benchmark.name.ljust(30), end="")
                sys.stdout.flush()
                duration = benchmark.run(transaction)
                print(format_duration(duration))

        else:
            print("No benchmarks to run")
Beispiel #6
0
def run():
    if config['generate_tree']:
        # drop existing database and recreate
        postgres_create_db(config['postgres_db'], DBNAME)

        connection = psycopg2.connect(config['benchmark_db'])
        tree = Tree(connection)

        with tree() as transaction:
            transaction.install()
            # create tree with test data
            generate_tree(transaction, config['levels'], config['per_level'])

    connection = psycopg2.connect(config['benchmark_db'])
    tree = Tree(connection)

    with tree() as transaction:
        postgres_analyze_db(transaction.cursor)

        # build a list of benchmarks to run
        benchmarks = create_benchmarks(transaction, config)
        benchmarks_to_run = []
        filter_benchmarks = config['filter_benchmarks']

        for b in benchmarks:
            if not filter_benchmarks or filter_benchmarks in b.name:
                benchmarks_to_run.append(b)

        print()

        if len(benchmarks_to_run):
            print("Running benchmarks..")

            for benchmark in benchmarks_to_run:
                print(benchmark.name.ljust(30), end="")
                sys.stdout.flush()
                duration = benchmark.run(transaction)
                print(format_duration(duration))

        else:
            print("No benchmarks to run")
Beispiel #7
0
 def generate_cell(self, data):
   return DataColumn.CELL_HTML.format(utils.format_duration(data[self._key]))
                                overwrite=args.force)
            fp_in_mem = read_blob(filename)
            for _tuple in fp_in_mem:
                try:
                    idx, fp, smiles = _tuple
                    tanimoto_sim = TanimotoSimilarity(ref, fp)
                    if tanimoto_sim >= args.tanimoto_threshold:
                        result = make_string(smiles, idx, tanimoto_sim)
                        results.append(result)
                        # # Save results every N found molecules
                        if len(results) >= 1000:
                            dump(results)
                            results = []
                except TypeError as e:
                    print(e)
            dump(results)
            print(f"Checked for {len(fp_in_mem)} molecules.")
        except FileExistsError:
            print(f"Files for blob already exist: f{filename} ")
    else:
        raise ValueError("Filetype unkown: {}".format(file_type))
    return


for filename in inputs:
    print("Check fps in blob:", filename)
    check_file(filename)

endtime = datetime.now()
print(format_duration(starttime, endtime))