add generation script for unique installs
This commit is contained in:
parent
2fe8a58670
commit
9c88194369
2 changed files with 61 additions and 0 deletions
56
code/unique.py
Normal file
56
code/unique.py
Normal file
|
|
@ -0,0 +1,56 @@
|
||||||
|
import csv
|
||||||
|
import json
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
|
|
||||||
|
def unique_install_csv(input_dir: Path, output_dir: Path) -> None:
|
||||||
|
output_file = output_dir / "unique_installs.csv"
|
||||||
|
with open(output_file, "w") as fw:
|
||||||
|
writer = csv.writer(fw)
|
||||||
|
writer.writerow(["date", "unique"])
|
||||||
|
|
||||||
|
for j in input_dir.glob("*.json"):
|
||||||
|
with open(j) as fr:
|
||||||
|
date = j.stem
|
||||||
|
data: dict[str, object] = {}
|
||||||
|
try:
|
||||||
|
data = json.load(fr)
|
||||||
|
except json.JSONDecodeError:
|
||||||
|
print(f"WARN: Could not decode JSON data for file {j}")
|
||||||
|
continue
|
||||||
|
|
||||||
|
if "UniqueInstalls" not in data or not isinstance(
|
||||||
|
data["UniqueInstalls"], int
|
||||||
|
):
|
||||||
|
print(
|
||||||
|
f"WARN: No correct json structure containing 'UniqueInstalls' field in file {j}"
|
||||||
|
)
|
||||||
|
continue
|
||||||
|
|
||||||
|
p_date = date
|
||||||
|
p_count = data["UniqueInstalls"]
|
||||||
|
writer.writerow([p_date, p_count])
|
||||||
|
|
||||||
|
|
||||||
|
def ensure_dirs(input_dir: Path, output_dir: Path):
|
||||||
|
if not input_dir.is_dir():
|
||||||
|
raise ValueError
|
||||||
|
output_dir.mkdir(exist_ok=True, parents=True)
|
||||||
|
|
||||||
|
|
||||||
|
def main(input: str, output: str) -> None:
|
||||||
|
input_dir = Path(input)
|
||||||
|
output_dir = Path(output)
|
||||||
|
ensure_dirs(input_dir, output_dir)
|
||||||
|
unique_install_csv(input_dir, output_dir)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
import sys
|
||||||
|
|
||||||
|
if not len(sys.argv) == 3:
|
||||||
|
print("Please provide exactly one input directory and one output directory.")
|
||||||
|
sys.exit(1)
|
||||||
|
inp = sys.argv[1]
|
||||||
|
out = sys.argv[2]
|
||||||
|
main(inp, out)
|
||||||
5
justfile
5
justfile
|
|
@ -1,2 +1,7 @@
|
||||||
|
default: kernels unique
|
||||||
|
|
||||||
kernels:
|
kernels:
|
||||||
python code/kernels.py input output
|
python code/kernels.py input output
|
||||||
|
|
||||||
|
unique:
|
||||||
|
python ./code/unique.py input output
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue