Skip to content
This repository has been archived by the owner on Oct 23, 2024. It is now read-only.

Commit

Permalink
Removed extraneous parts in OpenAtmos JSON
Browse files Browse the repository at this point in the history
Made the reactants and products in the reaction part of the JSON only show up if there are any.
  • Loading branch information
ecyr20 committed Apr 9, 2024
1 parent e734b66 commit a4fab65
Showing 1 changed file with 27 additions and 13 deletions.
40 changes: 27 additions & 13 deletions Services/OpenAtmosService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -116,26 +116,40 @@ public async Task<string> Get(Guid tag_mechanism_uuid)
JSON += ", \n";
}
var reactants = reactantProductListService.GetReactantsAsync(reaction.reactant_list_uuid).Result;
JSON += " \"reactants\": [ \n" +
" {\n";
foreach (ReactantsProducts reactant in reactants)
if(reactants.Count != 0)
{
JSON += " \"species name\": \"" + reactant.type + "\", \n";
JSON += " \"coefficient\": \"" + reactant.quantity + "\" \n";
JSON += " \"reactants\": [ \n" +
" {\n";
foreach (ReactantsProducts reactant in reactants)
{
JSON += " \"species name\": \"" + reactant.type + "\", \n";
JSON += " \"coefficient\": \"" + reactant.quantity + "\" \n";
}
JSON += " }\n" +
" ], \n";
}
JSON += " }\n" +
" ], \n";

var products = reactantProductListService.GetProductsAsync(reaction.product_list_uuid).Result;
JSON += " \"products\": [ \n" +

if(products.Count != 0)
{
JSON += " \"products\": [ \n" +
" {\n";
foreach (ReactantsProducts product in products)
foreach (ReactantsProducts product in products)
{
JSON += " \"species name\": \"" + product.type + "\", \n";
JSON += " \"coefficient\": \"" + product.quantity + "\" \n";
}
JSON += " }\n" +
" ]\n";
}

if(reactants.Count == 0 && products.Count == 0)
{
JSON += " \"species name\": \"" + product.type + "\", \n";
JSON += " \"coefficient\": \"" + product.quantity + "\" \n";
JSON = JSON.Remove(JSON.LastIndexOf(','));
JSON += "\n";
}
JSON += " }\n" +
" ]\n";

JSON += " },\n";
}
JSON = JSON.Remove(JSON.LastIndexOf(','));
Expand Down

0 comments on commit a4fab65

Please sign in to comment.