Skip to content

Commit

Permalink
Add: analyze surveys with schema version 2
Browse files Browse the repository at this point in the history
  • Loading branch information
TrueBrain committed Mar 17, 2024
1 parent a041375 commit e417780
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 7 deletions.
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
27 changes: 23 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,16 @@ def summarize_result(summary, fp):
summary[version]["summary"]["count"] += 1
summary[version]["summary"]["seconds"] += seconds

if schema >= 2:
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 +279,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

0 comments on commit e417780

Please sign in to comment.