def analyze(sites, start_date, end_date):
    data = {}

    for site in sites:
        # For each site, we extract the runs for the specified period, and from
        # them, offer counts and error logs
        runs = Run.objects.filter(site=site,
                                  start__gte=start_date,
                                  end__lte=end_date)

        # Error Logs

        # Iterate over each run, find every error log between its start and
        # end, and get the percentage of each kind.

        all_errors = ErrorLog.objects.filter(site=site,
                                             date_time__gte=start_date,
                                             date_time__lte=end_date)
        period_error_distribution = process_errors(all_errors)

        error_evolution = []

        for run in runs:
            errors = ErrorLog.objects.filter(site=site,
                                             date_time__gte=run.start,
                                             date_time__lte=run.end)

            run_time = datetime_to_unix(run.start)
            processed_errors = process_errors(errors)

            error_evolution += [{
                'date': run_time,
                'errors': processed_errors
            }]

        working = False
        if runs:
            last_run = runs.order_by('-start')[0]
            if 0 > last_run.scraped:
                working = True

        offers_log = [[datetime_to_unix(run.start), run.scraped]
                      for run in runs]
        analysis = SpiderLogAnalysis(working=working,
                                     times_run=len(runs),
                                     offers_log=offers_log,
                                     errors=period_error_distribution,
                                     error_evolution=error_evolution)
        data[site.name] = analysis

    return data
dataset/ETHPy150Open tryolabs/daywatch/daywatch/core/spider_logs.py/analyze/swapped operands of `>`