<commit_before>import io

import pandas as pd

from django.core.exceptions import ObjectDoesNotExist
from django.core.files.uploadedfile import SimpleUploadedFile
from django.core.management.base import BaseCommand, CommandError

from fat.models import Claimed, Fund, Expense

CSV_TO_IMPORT = 'old_funds.csv'

def conv_date(new_date):
    day, month, year = new_date.split('/')
    return "{}-{}-{}".format(year, month, day)

class Command(BaseCommand):
    help = "Import CSV (old_funds.csv) with funds from claimeds to the database."

    # TODO Make use of args and options.
    def handle(self, *args, **options):
        data =  pd.read_csv(CSV_TO_IMPORT)
        for idx, line in data.iterrows():
            try:
                this_claimed = Claimed.objects.get(forenames=line["Forename(s)"], surname=line["Surname"], selected=True)
                if line['Event type'] == 'Attending a conference/workshop':
                    fund_category = 'A'
                elif line['Event type'] == ' Organising a workshop (e.g. Software Carpentry)':
                    fund_category = 'H'
                elif line['Event type'] == 'Policy related fund':
                    fund_category = 'P'
                else:
                    fund_category = 'O'
                funds_dict = {
                        "claimed": this_claimed,
                        "category": fund_category,
                        "name": line["Event name"],
                        "url": line["Event website"] if pd.notnull(line["Event website"]) else "",
                        "country": line["Event Country"] if len(line["Event Country"]) == 2 else 'GB',
                        "city": line["Event City"],
                        "start_date": conv_date(line["Start date"]),
                        "end_date": conv_date(line["End date"]) if line["End date"] else conv_date(line["Start date"]),
                        "budget_request_travel": line["Travel costs"] if pd.notnull(line["Travel costs"]) else 0,<commit_msg>Fix bug on loadoldfunds<commit_after>import io

import pandas as pd

from django.core.exceptions import ObjectDoesNotExist
from django.core.files.uploadedfile import SimpleUploadedFile
from django.core.management.base import BaseCommand, CommandError

from fat.models import Claimed, Fund, Expense

CSV_TO_IMPORT = 'old_funds.csv'

def conv_date(new_date):
    day, month, year = new_date.split('/')
    return "{}-{}-{}".format(year, month, day)

class Command(BaseCommand):
    help = "Import CSV (old_funds.csv) with funds from claimeds to the database."

    # TODO Make use of args and options.
    def handle(self, *args, **options):
        data =  pd.read_csv(CSV_TO_IMPORT)
        for idx, line in data.iterrows():
            try:
                this_claimed = Claimed.objects.get(forenames=line["Forename(s)"], surname=line["Surname"], selected=True)
                if line['Event type'] == 'Attending a conference/workshop':
                    fund_category = 'A'
                elif line['Event type'] == ' Organising a workshop (e.g. Software Carpentry)':
                    fund_category = 'H'
                elif line['Event type'] == 'Policy related event':
                    fund_category = 'P'
                else:
                    fund_category = 'O'
                funds_dict = {
                        "claimed": this_claimed,
                        "category": fund_category,
                        "name": line["Event name"],
                        "url": line["Event website"] if pd.notnull(line["Event website"]) else "",
                        "country": line["Event Country"] if len(line["Event Country"]) == 2 else 'GB',
                        "city": line["Event City"],
                        "start_date": conv_date(line["Start date"]),
                        "end_date": conv_date(line["End date"]) if line["End date"] else conv_date(line["Start date"]),
                        "budget_request_travel": line["Travel costs"] if pd.notnull(line["Travel costs"]) else 0,
{'fraction_non_alphanumeric': 0.12242874845105328, 'fraction_numerical': 0.0009913258983890955, 'mean_word_length': 2.1335403726708075, 'pattern_counts': {'":': 18, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '353825', 'n_tokens_mistral': 1125, 'n_tokens_neox': 1068, 'n_words': 302}