Skip to content

Commit

Permalink
Fix/typescript (#11)
Browse files Browse the repository at this point in the history
* feat(afrl): add typescript to transform a csv

* fix(typescript): restore afrl project

* doc(typescript): index.md and readme.md

* fix(_config.yml): exclude node_modules

* feat(typescript/afrl): add short description

* changed AFRL TypeScript page wording

---------

Co-authored-by: nh916 <[email protected]>
  • Loading branch information
bearmit and nh916 authored Apr 14, 2023
1 parent 36a1411 commit 4a02288
Show file tree
Hide file tree
Showing 48 changed files with 7,391 additions and 65 deletions.
14 changes: 0 additions & 14 deletions .idea/.gitignore

This file was deleted.

4 changes: 2 additions & 2 deletions _config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,13 @@ plugins:
# Excluded items can be processed by explicitly listing the directories or
# their entries' file path in the `include:` list.
#
# exclude:
exclude:
- scripts/typescript/node_modules
# - .sass-cache/
# - .jekyll-cache/
# - gemfiles/
# - Gemfile
# - Gemfile.lock
# - node_modules/
# - vendor/bundle/
# - vendor/cache/
# - vendor/gems/
Expand Down
6 changes: 6 additions & 0 deletions scripts/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

File renamed without changes.
File renamed without changes.
20 changes: 20 additions & 0 deletions scripts/typescript/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
---
layout: default
title: AFRL README.md
published: false
---

# TypeScript ingestion scripts for CRIPT

This folder is a unique npm package shared between all ingestion scripts. Browse the `./src` folder.
# `npm i`

Will install this npm package and dependencies.

# This project contains several ingestion scripts

Note: scripts are still WIP.

- `afrl`: see [readme](src/afrl/README.md)
- `rcbc`: see [readme](src/rcbc/README.md)

6 changes: 4 additions & 2 deletions scripts/typescript/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ has_children: true
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css" integrity="sha512-iecdLmaskl7CVkqkXNQ/ZH/XLlvWZOJyj7Yy7tcenmpD1ypASozpmT/E0iPtmFIB46ZmdtAc9eNBvH0H/ZpiBw==" crossorigin="anonymous" referrerpolicy="no-referrer" />


# <i class="fa-solid fa-code"></i> TypeScript CRIPT Scripts
# <i class="fa-solid fa-code"></i> TS CRIPT Scripts

TypeScript script examples to prepare ingestion into [CRIPT](https://criptapp.org/).


Example TypeScript CRIPT Scripts built with the used to upload polymer data to [CRIPT](https://criptapp.org/)

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
"description": "Set of typescript code to convert raw data (*.csv, *.ts) to CRIPT *.json format",
"main": "index.js",
"scripts": {
"afrl": "npx ts-node src/afrl/index.ts",
"rcbc": "npx ts-node src/rcbc/index.ts",
"afrl": "npx ts-node ./src/afrl/index.ts",
"rcbc": "npx ts-node ./src/rcbc/index.ts",
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "Bérenger Dalle-Cort, CRIPT, MIT",
Expand All @@ -14,5 +14,8 @@
"csvtojson": "^2.0.10",
"ts-node": "^10.9.1",
"typescript": "^5.0.3"
},
"devDependencies": {
"tsconfig-paths": "^4.2.0"
}
}
31 changes: 31 additions & 0 deletions scripts/typescript/src/afrl/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# AFRL CSV to JSON
## How to use?

from project root, run `npm run afrl`

Will run the AFRL CSV to JSON script and produce multiple JSON in the `out/afrl` folder from the CSV file present in `src/afrl/data` folder.

After a run, check the *.errors.json file to be sure you do not skip important data.
Then, you can upload the data to CRIPT using curl:

```
curl -X POST -H "Content-Type: application/json" -d "@./out/afrl/afrl-transformed.min.json" <host>/project/ --header "authorization: Bearer <token>"
```

## How it works?

Step by step of what the script does on a macro level (for more details look at the source code).

- Load the data (`src/data/*.csv`) as an `Array<AFRLData>`.
- For each CSV line (or object), we create 3 `Material`s (a mixture, a solvent, and a polymer) with some `Property`, `Condition` and `Citation` (`doi` is stored in a `Reference`) on it.
- Each type of material is registered in a dedicated `Inventory`.
- Inventories are store in a single `Collection` which is in a single `Project`.
- The `Project` is serialized as a single JSON (in two version, one minified and an other human-readable).
- If some data cannot be transformed, logs are added to the *.errors.json file.


## History

This script was using Python originally (see [here](../../../python_sdk_scripts/AFRL/)), last commit was from December 2022. I figured out the python version was existing **after** starting this task, that's why I started using typescript. However, I couldn't use Python (no much experience and culture) and the PythonSDK (still in development), so I decided to continue this way.

Berenger.
Loading

0 comments on commit 4a02288

Please sign in to comment.