<jupyter_start><jupyter_text><jupyter_code>import sys

!{sys.executable} -m pip install --force-reinstall --upgrade "git+https://github.com/HausReport/ClubRaiders.git#egg=craid"
import craid.eddb.loader.DataProducer as dp
import pandas as pd
import logging
import plotly.graph_objs as go
from numpy import *


logging.getLogger().addHandler(logging.StreamHandler())
logging.getLogger().level = logging.DEBUG

arrays = dp.getDataArrays()
df: pd.DataFrame = arrays['dataFrame']
from craid.eddb.faction.SquadronXYZ import SquadronXYZ
from craid.club.regions.RegionFactory import RegionFactory
from django.contrib.admin.utils import flatten
sNames = []
sSystems = []
sRegions = []

for squad in SquadronXYZ.myDict.keys():
  systems = SquadronXYZ.myDict.get(squad)
  for sysName in systems.keys():
    sysLoc = systems.get(sysName)
    if sysLoc is None:
      continue
    sNames.append(squad)
    sSystems.append(sysName)
    sReg = RegionFactory.getRegion(sysLoc[0], sysLoc[1], sysLoc[2])
    sRegions.append(sReg.getNumber())

df = pd.DataFrame(list(zip(sNames, sSystems, sRegions)), 
               columns =['Squadron Name', 'System', 'Region']) 
df

def getSquadronsByRegion(region=1, cutoff=0) -> pd.DataFrame:
  tmp = df[ df['Region']==region].groupby(['Squadron Name']).agg( {'Region': 'count'}).reset_index()
  tmp.columns = ['Squadron Name','Systems in Region']
  tmp = tmp[ tmp['Systems in Region'] >= cutoff]
  return tmp.sort_values('Systems in Region', ascending=False)
getSquadronsByRegion(1,cutoff=2)
foo = getSquadronsByRegion(1,2)
print("| Squadron | # Systems |")
print("| -------- | --------- |")

for index, row in foo.iterrows():
    print("|" + row['Squadron Name'] + "|" + str(row['Systems in Region']) + "|")
def getClubFactionsInRegion(num: int) -> str:
  dataFrame: pd.DataFrame = arrays['dataFrame']
  foo = dataFrame[ dataFrame['regionNumber']==num][['factionName']]
  foo = foo.drop_duplicates()
  bar = flatten(foo.values.tolist())
  return " - ".join(bar)
for region in RegionFactory.regionDict.values():
  regNum = region.getNumber()
  if regNum == 0:
    continue
  regName = region.getTitle()
  print(f"\n## Region # {regNum}: {regName}")
  clubFacs = getClubFactionsInRegion(regNum)
  print(f"_Regional Club Factions: {clubFacs}_\n")
  if regNum==3:
    cutoff = 0
  else:
    cutoff = 2
  foo = getSquadronsByRegion(regNum,cutoff)
  print("| Squadron | # Systems |")
  print("| -------- | --------- |")

  for index, row in foo.iterrows():
    print("|" + row['Squadron Name'] + "|" + str(row['Systems in Region']) + "|")
def getView(reg, dataFrame):
  return dataFrame[dataFrame.apply(lambda x: reg.contains(x.x, x.y, x.z), axis=1)]

#from craid.appHelpers import AnnoyingCrap

squad = "Sirius Inc"
reg = RegionFactory.getSquadronRegion(squad,  64, "rgb(0,0,255)")
frame : pd.DataFrame = arrays['dataFrame']
view = getView(reg, frame)
view
#view['htext'] = view[['systemName', 'factionName']].agg('\n'.join, axis=1)

foo= view[['factionName']]
foo = foo.drop_duplicates()
bar = flatten(foo.values.tolist())
#return 
" - ".join(bar)
reg.getFigure(view)
view<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.17173982697853252, 'fraction_numerical': 0.007049022749118872, 'mean_word_length': 4.676363636363637, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 8, 'https://': 1, '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}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '588578', 'license': 'BSD-3-Clause', 'n_tokens_mistral': 1127, 'n_tokens_neox': 1105, 'n_words': 231, 'path': 'notebooks/Squadrons.ipynb', 'repo_name': 'HausReport/ClubRaiders', 'size': '3121'}