def handle(self, *args, **options):
        start = datetime.now()  # Measure the time it takes to run the script.
        day = options['date']
        if not day:
            day = (datetime.now() - timedelta(days=1)).strftime('%Y-%m-%d')
        folder = args[0] if args else 'hive_results'
        folder = path.join(settings.TMP_PATH, folder, day)
        sep = options['separator']
        groups = ('version', 'status', 'app', 'os', 'locale')
        group_filepaths = []
        # Make sure we're not trying to update with mismatched data.
        for group in groups:
            filepath = path.join(folder, 'update_counts_by_%s.hive' % group)
            if get_date_from_file(filepath, sep) != day:
                raise CommandError('%s file contains data for another day' %
                                   filepath)
            group_filepaths.append((group, filepath))
        # First, make sure we don't have any existing counts for the same day,
        # or it would just increment again the same data.
        UpdateCount.objects.filter(date=day).delete()

        # Memoize the addons and the UpdateCounts.
        update_counts = {}
        # Perf: preload all the addons once and for all.
        # This builds a dict where each key (the addon guid we get from the
        # hive query) has the addon_id as value.
        guids_to_addon = (dict(Addon.objects.exclude(guid__isnull=True)
                                            .exclude(type=amo.ADDON_PERSONA)
                                            .values_list('guid', 'id')))

        index = -1
        for group, filepath in group_filepaths:
            with codecs.open(filepath, encoding='utf8') as results_file:
                for line in results_file:
                    index += 1
                    if index and (index % 1000000) == 0:
                        log.info('Processed %s lines' % index)

                    splitted = line[:-1].split(sep)

                    if ((group == 'app' and len(splitted) != 6)
                            or (group != 'app' and len(splitted) != 5)):
                        log.debug('Badly formatted row: %s' % line)
                        continue

                    if group == 'app':
                        day, addon_guid, app_id, app_ver, count, \
                            update_type = splitted
                    else:
                        day, addon_guid, data, count, update_type = splitted

                    addon_guid = addon_guid.strip()
                    if update_type:
                        update_type.strip()

                    # Old versions of Firefox don't provide the update type.
                    # All the following are "empty-like" values.
                    if update_type in ['0', 'NULL', 'None', '', '\N',
                                       '%UPDATE_TYPE%']:
                        update_type = None

                    try:
                        count = int(count)
                        if update_type:
                            update_type = int(update_type)
                    except ValueError:  # Badly formatted? Drop.
                        continue

                    # The following is magic that I don't understand. I've just
                    # been told that this is the way we can make sure a request
                    # is valid:
                    # > the lower bits for updateType (eg 112) should add to
                    # > 16, if not, ignore the request.
                    # > udpateType & 31 == 16 == valid request.
                    if update_type and update_type & 31 != 16:
                        log.debug("Update type doesn't add to 16: %s" %
                                  update_type)
                        continue

                    # Does this addon exist?
                    if addon_guid and addon_guid in guids_to_addon:
                        addon_id = guids_to_addon[addon_guid]
                    else:
                        log.debug(u"Addon {guid} doesn't exist."
                                  .format(guid=addon_guid.strip()))
                        continue

                    # Memoize the UpdateCount.
                    if update_counts in addon_guid:
                        uc = update_counts[addon_guid]
                    else:
                        uc = UpdateCount(date=day, addon_id=addon_id, count=0)
                        update_counts[addon_guid] = uc

                    # We can now fill the UpdateCount object.
                    if group == 'version':
                        self.update_version(uc, data, count)
                        # Use this count to compute the global number of daily
                        # users for this addon.
                        uc.count += count
                    elif group == 'status':
                        self.update_status(uc, data, count)
                    elif group == 'app':
                        self.update_app(uc, app_id, app_ver, count)
                    elif group == 'os':
                        self.update_os(uc, data, count)
                    elif group == 'locale':
                        self.update_locale(uc, data, count)

        # Make sure the locales and versions fields aren't too big to fit in
        # the database. Those two fields are the only ones that are not fully
        # validated, so we could end up with just anything in there (spam,
        # buffer overflow attempts and the like).
        # We don't care that they will increase the numbers, but we do not want
        # those to break the process because of a "Data too long for column
        # 'version'" error.
        # The database field (TEXT), can hold up to 2^16 = 64k characters.
        # If the field is longer than that, we we drop the least used items
        # (with the lower count) until the field fits.
        for addon_guid, update_count in update_counts.iteritems():
            self.trim_field(update_count.locales)
            self.trim_field(update_count.versions)

        # Create in bulk: this is much faster.
        UpdateCount.objects.bulk_create(update_counts.values(), 100)
        for udate_count in update_counts.values():
            save_stats_to_file(update_count)
        log.info('Processed a total of %s lines' % (index + 1))
        log.debug('Total processing time: %s' % (datetime.now() - start))

        # Clean up files.
        for _, filepath in group_filepaths:
            log.debug('Deleting {path}'.format(path=filepath))
            unlink(filepath)
dataset/ETHPy150Open mozilla/addons-server/src/olympia/stats/management/commands/update_counts_from_file.py/Command.handle/swapped operands of `in`