# ---
# jupyter:
#   jupytext:
#     text_representation:
#       extension: .py
#       format_name: light
#       format_version: '1.5'
#       jupytext_version: 1.14.4
#   kernelspec:
#     display_name: Python 3
#     name: python3
# ---

# + [markdown] id="view-in-github" colab_type="text"
# <a href="https://colab.research.google.com/github/HausReport/ClubRaiders/blob/master/ANN.ipynb" target="_parent"><img src="https://colab.research.google.com/assets/colab-badge.svg" alt="Open In Colab"/></a>

# + id="QqW422GGF51M" colab_type="code" colab={}
import pandas as pd
from typing import List
from datetime import datetime
from random import randint
from dateutil.relativedelta import *


# + id="T9-2dtJ5GlDz" colab_type="code" colab={}
    factionName: List[str] = []
    systemName: List[str] = []
    population: List[int] = []
    influence: List[float] = []
    updated: List[datetime] = []

# + id="Ad7IoGBFHUED" colab_type="code" colab={}
factionName: List[str] = []
systemName: List[str] = []
population: List[int] = []
influence: List[float] = []
updated: List[datetime] = []
    
randStrs = ['foo', 'bar', 'guh']

def randStr() -> str:
  global randStrs
  return randStrs[randint(0, len(randStrs))]

def seqStr(i: int) -> str:
  global randStrs
  return randStrs[i % len(randStrs)]

start_date = datetime.strptime("2020-06-01", "%Y-%m-%d")


for fac in ['foo','bar','guh']:
  upd = start_date
  for sys in ['sol','celeano']:
    for i in range(0,5):
      factionName.append( fac)
      systemName.append( sys)
      population.append(10000)
      influence.append(.33)

      day = randint(2,4)
      upd = upd + relativedelta(hours=day*8)
      updated.append(upd)


data = { 'systemName' : systemName,
         'factionName' : factionName,
         'population' : population,
         'influence'  : influence,
         'updated' : updated
        }
df = pd.DataFrame(data = data)


# + id="rTuwQUxqF9jl" colab_type="code" colab={"base_uri": "https://localhost:8080/", "height": 1000} outputId="cd6e390e-82ce-454f-d259-55d580b5884d"
# prepare data

df['updated'] = df.updated.dt.round("D") 
df = df.sort_values(by=['systemName', 'factionName','updated'])

# this drops out all data that doesn't have at least 2 days in a row
systems = df['systemName'].unique().tolist()
holder = pd.DataFrame()

for sys in systems:
  print(sys)
  sysSlice = df[ df['systemName'] ==sys]
  facs = sysSlice['factionName'].unique().tolist()
  for fac in facs:
    print("\t"+ fac)
    facSlice = sysSlice[ sysSlice['factionName'] == fac].reset_index()
    facSlice['diff1'] = facSlice.updated.diff(periods=1).dt.days.abs()
    facSlice['diff2'] = facSlice.updated.diff(periods=-1).dt.days.abs()
    facSlice = facSlice.fillna(999.0) 
    facSlice['diffz'] = facSlice[['diff1','diff2']].min(axis=1)
    facSlice = facSlice[ facSlice['diffz'] <=1.0]
    facSlice = facSlice.drop(['diff1','diff2','diffz'],  axis=1)
    holder = holder.append(facSlice.copy(), ignore_index=True)


holder


# + id="66XtWhzA8Y60" colab_type="code" colab={}
def minAbs(x1: float, x2: float) -> float:
  return min ( abs(x1), abs(x2))

StarcoderdataJupyterScriptsDedupFiltered