Skip to content

Commit

Permalink
add naive objective import script
Browse files Browse the repository at this point in the history
  • Loading branch information
digitalfox committed May 17, 2024
1 parent 422fcc6 commit e02f5d0
Showing 1 changed file with 48 additions and 0 deletions.
48 changes: 48 additions & 0 deletions scripts/import_objectives.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#!/usr/bin/env python3
# coding: utf-8

"""
Import objectives and rates from CSV format
@author: Sébastien Renard ([email protected])
@license: AGPL v3 or newer (http://www.gnu.org/licenses/agpl-3.0.html)
"""

import csv
from datetime import datetime
import sys
import os
from os.path import abspath, join, pardir, dirname


# # Setup django envt & django imports
PYDICI_DIR = abspath(join(dirname(__file__), pardir))
os.environ['DJANGO_SETTINGS_MODULE'] = "pydici.settings"

sys.path.append(PYDICI_DIR) # Add project path to python path

# Ensure we are in the good current working directory (pydici home)
os.chdir(PYDICI_DIR)

# Init and model loading
from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()

# Pydici imports
from people.models import Consultant, RateObjective

objectives = csv.reader(open(sys.argv[1], "r"))

for line in objectives:
if not line[0] or line[0]=="Consultant":
continue
try:
c = Consultant.objects.get(trigramme=line[0])
except:
print(f"Warning, no consultant for {line[0]}")
continue
start = datetime.strptime(line[21], "%Y-%m-%d")
prod_rate = float(line[10].strip("%"))
daily_rate = int(line[7])
RateObjective.objects.get_or_create(consultant=c, start_date=start, rate=daily_rate, rate_type="DAILY_RATE")
RateObjective.objects.get_or_create(consultant=c, start_date=start, rate=prod_rate, rate_type="PROD_RATE")

0 comments on commit e02f5d0

Please sign in to comment.