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 submission schema and tools to generate it (New) #770

Merged
merged 8 commits into from
Dec 1, 2023
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules
84 changes: 84 additions & 0 deletions submission-schema/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
# Checkbox submission schema

In this folder you can find the schema for the submission.json that's sent to certification.canonical.com as part of the submission, as well as the instruction and tools needed to recreate that schema.

## The schema

`schema.json` contains the schema that was generated using ~2000 latest (at the time of writing) submissions uploaded to C3.

## Generating schema from scratch

The `schema.json` can be generated using a existing submission tarballs.
Follow the steps below to generate a fresh `schema.json`

### Obtaining submission tarballs

If you have access to the Hexr repository, you will find a useful
[helper program](https://github.com/canonical/hexr/blob/main/scripts/download_submissions.py) that downloads a series of submissions from C3.

Follow the [README for that tool](https://github.com/canonical/hexr/blob/main/scripts/README.md) to get started.

You will have to tweak the `LIMIT` parameter to download more sessions.
Also note that at the time of writing, this tool is designed to process the submissions
after downloading and then dispose them. Deleting the `os.remove` calls will
make the submission tarballs stay on the filesystem.

### Unpacking submission.json from the tarballs

Navigate to the directory where the downloaded scripts are located, and extract the json files. For instance

```bash
#!/bin/bash

TARGET_DIR="../jsons"

# Create the directory if it doesn't exist.
mkdir -p "$TARGET_DIR"

# Loop through each .tar.xz file in the current directory.
for file in *.tar.xz
do
# Get the base name of the file without the extension.
base_name="$(basename "$file" .tar.xz)"

# Extract only the submission.json file.
tar -xvf "$file" --wildcards --no-anchored 'submission.json' -O > "${TARGET_DIR}/${base_name}.json"
done

```

### Generating Python loader out of the schema

`quicktype` can be used to generate the schema, as well as Python classes representing submission data.

#### Getting quicktype

1. Install `nodejs` [using the nodesource.com provided Node.js binary distribution](https://github.com/nodesource/distributions#nodejs).
mz2 marked this conversation as resolved.
Show resolved Hide resolved

2. Install dependencies (`quicktype` and its transitive dependencies are installed under `./submission-schema/node_modules`).

```bash
cd submission-schema
npm install
```

#### Generating schema with Quicktype from input JSON data

```bash
npm run generate-schema-from-input-jsons
```

#### Generating Python class with Quicktype using the existing schema

```bash
npm run generate-python-types-from-schema
```


#### Generating Python class with Quicktype using submissions

Python classes can be created directly from input JSONs.
mz2 marked this conversation as resolved.
Show resolved Hide resolved

```bash
npm run generate-python-types-from-input-jsons
```
Loading