# %%
PROJECT_PATH = '/home/md/Work/ligalytics/leagues_develop/'
import os, sys
sys.path.insert(0, PROJECT_PATH)
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "leagues.settings")
os.environ["DJANGO_ALLOW_ASYNC_UNSAFE"] = "true"

from leagues import settings
settings.DATABASES['default']['NAME'] = PROJECT_PATH+'/db.sqlite3'
# settings.DATABASES['default']['ENGINE'] = 'django.db.backends.postgresql_psycopg2'
# settings.DATABASES['default']['HOST'] = '0.0.0.0'
# settings.DATABASES['default']['PORT'] = '5432'
# settings.DATABASES['default']['USER'] = 'postgres'
# settings.DATABASES['default']['PASSWORD'] = 'secret123'
# settings.DATABASES['default']['NAME'] = 'mypgsqldb'
# settings.DATABASES['default']['ATOMIC_REQUESTS'] = False
# settings.DATABASES['default']['AUTOCOMMIT'] = True
# settings.DATABASES['default']['CONN_MAX_AGE'] = 0
# settings.DATABASES['default']['CONN_HEALTH_CHECKS'] = False
# settings.DATABASES['default']['OPTIONS'] = {}

# os.environ["XPRESSDIR"] = "/opt/xpressmp"
# os.environ["XPRESS"] = "/opt/xpressmp/bin"
# os.environ["LD_LIBRARY_PATH"] = os.environ["XPRESSDIR"] + "/lib"
# os.environ["DYLD_LIBRARY_PATH"] = os.environ["XPRESSDIR"] + "/lib"
# os.environ["SHLIB_PATH"] = os.environ["XPRESSDIR"] + "/lib"
# os.environ["LIBPATH"] = os.environ["XPRESSDIR"] + "/lib"
# os.environ["PYTHONPATH"] = os.environ["XPRESSDIR"] + "/lib"
# os.environ["CLASSPATH"] = os.environ["XPRESSDIR"] + "/lib/xprs.jar"
# os.environ["CLASSPATH"] = os.environ["XPRESSDIR"] + "/lib/xprb.jar" + os.pathsep + os.environ["CLASSPATH"]
# os.environ["CLASSPATH"] = os.environ["XPRESSDIR"] + "/lib/xprm.jar" + os.pathsep + os.environ["CLASSPATH"]
# os.environ["PATH"] = os.environ["XPRESSDIR"] + "/bin" + os.pathsep + os.environ["PATH"]


import django
django.setup()

from scheduler.models import *
import pulp
from pulp import lpSum, value, XPRESS, GUROBI, PULP_CBC_CMD
from django.db.models import Q
from django.template.loader import render_to_string

from qualifiers.models import *
from common.models import GlobalTeam, GlobalCountry
from scheduler.models import Season, Scenario, Team, DayObj, CountryClash, Country

from qualifiers.draws import groupTeams, optimize_inversions4
from scheduler.solver.tasks.optimize import optimize


from referees.helpers import use_referees, import_deb_delegates, seed_rounds_from_days, generate_distance_matrix

from referees.models import RefGame, Role


import random
import time
import json
import csv
import networkx as nx
import matplotlib.pyplot as plt
from datetime import timedelta
# %%

scenario = Scenario.objects.get(id=24)

# %%

# use_referees(scenario.id)



import_deb_delegates(scenario)


generate_distance_matrix(scenario.season.id)
# %%

# season = scenario.season



# %%

# seed_rounds_from_days(scenario.season.id)

# Role.objects.all().delete()
# Role.objects.create(season=season, name="Referee", min_required=2, max_required=2)
# Role.objects.create(season=season,name="Linesmen", min_required=2, max_required=2)
# %%