-
Notifications
You must be signed in to change notification settings - Fork 0
/
universe.py
50 lines (40 loc) · 1.5 KB
/
universe.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import os
from os import walk
from constants import STAR_DIRECTORY
import pandas as pd
from rich.table import Table
from starsystem import load_starsystem_yaml
def universe_save():
list_systems = []
path_starsystems = os.path.abspath(STAR_DIRECTORY)
for (dirpath, dirnames, filenames) in walk(path_starsystems):
print("Collecting filenames")
for file in filenames:
system = load_starsystem_yaml(file)
list_systems.append(system)
# Convert list of dicts to a dataframe
system_df = pd.DataFrame(list_systems)
link = os.path.abspath(STAR_DIRECTORY)+"universe.csv"
#save to the star directory
system_df.to_csv(link, index=True)
return link
def build_universe_table():
list_systems = []
path_starsystems = os.path.abspath(STAR_DIRECTORY)
for (dirpath, dirnames, filenames) in walk(path_starsystems):
print("Collecting filenames")
for file in filenames:
system = load_starsystem_yaml(file)
list_systems.append(system)
# Convert list of dicts to a dataframe
system_df = pd.DataFrame(list_systems)
# Create a Table object
table = Table(title="Visited Systems")
# Add columns from the DataFrame
for column_name in system_df.columns:
table.add_column(column_name)
# Add rows from the DataFrame
for index, row in system_df.iterrows():
row = row.str.split(', ', expand=True)
table.add_row(str(row)) # Unpack row values as arguments
return table