Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add: analyze surveys with schema version 2 #46

Merged
merged 1 commit into from
Mar 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions _layouts/summary.html
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,14 @@ <h3>Survey Result Summary - {{ page.name }}</h3>
<tr>
<td style="width: 40px;"></td>
<td><pre>{{ line[0] }}</pre></td>
{% if percentage == "0.0" %}
<td style="text-align: right;">&lt;0.1%</td>
{% if line[0] == "average_size" %}
<td style="text-align: right;">{{ line[1] | divided_by: 1024 }} KiB</td>
{% else %}
<td style="text-align: right;">{{ percentage }}%</td>
{% if percentage == "0.0" %}
<td style="text-align: right;">&lt;0.1%</td>
{% else %}
<td style="text-align: right;">{{ percentage }}%</td>
{% endif %}
{% endif %}
</tr>
{% endfor %}
Expand Down
28 changes: 24 additions & 4 deletions analysis/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
"info.os.version", # OS specific setting, Not interesting.
"key", # Not interesting.
"schema", # Not interesting.
"session", # Processed differently.
]


Expand Down Expand Up @@ -175,9 +176,14 @@ def summarize_setting(summary, version, seconds, path, data):

def summarize_result(summary, fp):
data = json.loads(fp.read())
schema = data["schema"]

try:
seconds = data["game"]["timers"]["seconds"]
if schema == 1:
seconds = data["game"]["timers"]["seconds"]
else:
seconds = data["session"]["seconds"]

ticks = data["game"]["timers"]["ticks"]
except KeyError:
# Invalid (or very old) survey result.
Expand Down Expand Up @@ -217,9 +223,17 @@ def summarize_result(summary, fp):
summary[version]["summary"]["count"] += 1
summary[version]["summary"]["seconds"] += seconds

# Depending whether the game was saved, we see a savegame-size or not.
if schema >= 2 and "savegame_size" in data["session"]:
summary[version]["savegame"]["count"] += 1
summary[version]["savegame"]["size"] += data["session"]["savegame_size"]

if "ids" not in summary[version]["summary"]:
summary[version]["summary"]["ids"] = set()
summary[version]["summary"]["ids"].add(data["id"])
if schema == 1:
summary[version]["summary"]["ids"].add(data["id"])
else:
summary[version]["summary"]["ids"].add(data["session"]["id"])


def summarize_archive(summary, filename):
Expand Down Expand Up @@ -266,17 +280,23 @@ def main():
remove_version.append(version)
break

if path == "savegame":
if data["count"] != 0:
data["average_size"] = int(data["size"] / data["count"])
del data["size"]
del data["count"]

if path.startswith("game.settings.display_opt.") or path.startswith("game.settings.extra_display_opt."):
data["false"] = version_summary["summary"]["seconds"] - data["true"]

total = sum(data.values())

# Check if it adds up to the total; if not, it is (most likely) an OS specific setting.
if path != "summary" and total != version_summary["summary"]["seconds"]:
if path not in ("summary", "savegame") and total != version_summary["summary"]["seconds"]:
data["(not reported)"] = version_summary["summary"]["seconds"] - total

# Collapse entries below 0.1% to a single (other) entry, and not true/false.
if path not in ("summary", "reason"):
if path not in ("summary", "reason", "savegame"):
collapse = []
for key, value in data.items():
if value / total < 0.001 and key not in ("true", "false", "(not reported)"):
Expand Down
Loading