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

Developer template request #205

Merged
merged 10 commits into from
Sep 22, 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
96 changes: 95 additions & 1 deletion package-lock.json

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

7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,11 @@
},
"homepage": "https://github.com/nfdi4plants/arcAPI#readme",
"dependencies": {
"fable-library": "^1.1.1"
"fable-library": "^1.1.1",
"isomorphic-fetch": "^3.0.0"
},
"devDependencies": {
"mocha": "^10.2.0",
"mkdirp": "3.0.1"
"mkdirp": "3.0.1",
"mocha": "^10.2.0"
}
}
2 changes: 2 additions & 0 deletions paket.dependencies
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ storage: none
framework: net6.0, netstandard2.0

nuget Fable.Core ~> 4.0.0
nuget Fable.Fetch 2.6.0
nuget Fable.SimpleHttp 3.5.0
nuget FSharp.Core
nuget FsSpreadsheet 4.1.0

Expand Down
39 changes: 39 additions & 0 deletions paket.lock
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,49 @@ NUGET
Expecto (9.0.4)
FSharp.Core (>= 4.6)
Mono.Cecil (>= 0.11.3)
Fable.Browser.Blob (1.3)
Fable.Core (>= 3.0)
FSharp.Core (>= 4.7.2)
Fable.Browser.Dom (2.14)
Fable.Browser.Blob (>= 1.3)
Fable.Browser.Event (>= 1.5)
Fable.Browser.WebStorage (>= 1.2)
Fable.Core (>= 3.2.8)
FSharp.Core (>= 4.7.2)
Fable.Browser.Event (1.5)
Fable.Browser.Gamepad (>= 1.1)
Fable.Core (>= 3.0)
FSharp.Core (>= 4.7.2)
Fable.Browser.Gamepad (1.2)
Fable.Core (>= 3.0)
FSharp.Core (>= 4.7.2)
Fable.Browser.WebStorage (1.2)
Fable.Browser.Event (>= 1.5)
Fable.Core (>= 3.0)
FSharp.Core (>= 4.7.2)
Fable.Browser.XMLHttpRequest (1.3)
Fable.Browser.Blob (>= 1.3)
Fable.Browser.Event (>= 1.5)
Fable.Core (>= 3.0)
FSharp.Core (>= 4.7.2)
Fable.Core (4.0)
Fable.Fetch (2.6)
Fable.Browser.Blob (>= 1.2)
Fable.Browser.Event (>= 1.5)
Fable.Core (>= 3.7.1)
Fable.Promise (>= 2.2.2)
FSharp.Core (>= 4.7.2)
Fable.Mocha (2.16)
Fable.Core (>= 3.0)
FSharp.Core (>= 4.7)
Fable.Promise (3.2)
Fable.Core (>= 3.7.1)
FSharp.Core (>= 4.7.2)
Fable.SimpleHttp (3.5)
Fable.Browser.Dom (>= 1.0)
Fable.Browser.XMLHttpRequest (>= 1.1)
Fable.Core (>= 3.0)
FSharp.Core (>= 4.6.2)
FSharp.Core (7.0.400)
FsSpreadsheet (4.1)
Fable.Core (>= 4.0)
Expand Down
86 changes: 28 additions & 58 deletions playground/KevinF.fsx
Original file line number Diff line number Diff line change
@@ -1,72 +1,42 @@
#r "nuget: Fable.Core, 4.0.0"
#r "nuget: FsSpreadsheet, 2.0.2"
#r "nuget: FsSpreadsheet.ExcelIO, 2.0.2"
#r "nuget: Thoth.Json.Net, 11.0.0"
#r "nuget: Fable.SimpleHttp, 3.5.0"
#r "nuget: Fable.Promise, 3.2.0"
#r "nuget: Fable.Fetch, 2.6.0"
#I @"../src\ARCtrl/bin\Debug\netstandard2.0"
#r "ISA.dll"
#r "Contract.dll"
#r "FileSystem.dll"
#r "ISA.Spreadsheet.dll"
#r "CWL.dll"
#r "ARCtrl.ISA.dll"
#r "ARCtrl.Contract.dll"
#r "ARCtrl.FileSystem.dll"
#r "ARCtrl.ISA.Spreadsheet.dll"
#r "ARCtrl.CWL.dll"
#r "ARCtrl.dll"

//#i @"nuget: C:/Users/Kevin/source/repos/ISADotNet/pkg/"
//#r "nuget: ARC"
open Thoth.Json.Net

let [<Literal>] rootPath = @"C:\Users\Kevin\Desktop\TestARC"
open Contract
open ARCtrl
open ARCtrl.FileSystem

module ARC_IO =
open FsSpreadsheet
open FsSpreadsheet.ExcelIO
let readFilePaths (arcPath: string) =
System.IO.Directory.EnumerateFiles(arcPath,"*",System.IO.SearchOption.AllDirectories)
|> Array.ofSeq
|> Array.map (fun p -> System.IO.Path.GetRelativePath(rootPath, p))

let fullfillREADContract (arcRoot: string) (c: Contract) =
let p = System.IO.Path.Combine [|arcRoot; c.Path|]
match c with
| {Operation = READ} ->
let dto = DTO.Spreadsheet <| FsWorkbook.fromXlsxFile(p)
{c with DTO = Some dto}
| _ -> failwith "Tried reading from non-READ contract."

let fullfillREADContracts (arcRoot: string) (cArr: Contract []) =
cArr |> Array.map (fullfillREADContract arcRoot)

let initExistingARC (arcRootPath: string) =
let arc = readFilePaths arcRootPath |> ARC.fromFilePaths
let contracts = arc.getReadContracts() |> fullfillREADContracts arcRootPath
arc.addISAFromContracts(contracts)

let myarc = ARC_IO.initExistingARC(rootPath)

let newArcPath = System.IO.Path.Combine(__SOURCE_DIRECTORY__, "TestArc")

open ARCtrl.ISA
open FsSpreadsheet
open FsSpreadsheet.ExcelIO
open ARCtrl.ISA.Spreadsheet

module WriteContracts =

let getInvestigationPath() = Path.combineMany [|ARCtrl.Path.InvestigationFileName|]
open ARCtrl.Templates
open ARCtrl.Templates.Json

let createInvestigation (investigation: ArcInvestigation) =
let investigationFile = ArcInvestigation.toFsWorkbook (investigation)
let investigationFilePath = getInvestigationPath ()
let investigationContract = Contract.createCreate(investigationFilePath,DTOType.ISA_Investigation, DTO.Spreadsheet investigationFile)
investigationContract
let path = @"C:\Users\Kevin\source\repos\ARCtrl\playground"

let baseUrl = @"https://github.com/nfdi4plants/Swate-templates/releases/download/latest/templates.json"

let writeNewContracts (investigation: ArcInvestigation) =
let contracts = ResizeArray()
// root items
let investigationContract = WriteContracts.createInvestigation investigation
contracts.Add(investigationContract)
contracts
let decoder : Thoth.Json.Net.Decoder<Map<string,Template>> = Thoth.Json.Net.Decode.dict Json.Template.decode

let dict (json: string) =
json
|> Thoth.Json.Net.Decode.fromString decoder

let GetTemplates() =
ARCtrl.WebRequest.downloadFile baseUrl (fun json ->
let mapResult = dict json
match mapResult with
| Ok map -> printfn "%A" map.Count
| Error exn -> failwith "Unable to parse json to template []"
)
|> Async.RunSynchronously

writeNewContracts arc
GetTemplates()
1 change: 1 addition & 0 deletions playground/UNITTEST_Template.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"id":"e83957e9-8865-498f-8c3e-629da103037c","table":[{"name":"My Table","inputs":[{"name":"Source 0","characteristics":[]},{"name":"Source 1","characteristics":[]},{"name":"Source 2","characteristics":[]},{"name":"Source 3","characteristics":[]},{"name":"Source 4","characteristics":[]},{"name":"Source 5","characteristics":[]},{"name":"Source 6","characteristics":[]},{"name":"Source 7","characteristics":[]},{"name":"Source 8","characteristics":[]},{"name":"Source 9","characteristics":[]}],"outputs":[{"name":"Output 0","type":"Raw Data File"},{"name":"Output 1","type":"Raw Data File"},{"name":"Output 2","type":"Raw Data File"},{"name":"Output 3","type":"Raw Data File"},{"name":"Output 4","type":"Raw Data File"},{"name":"Output 5","type":"Raw Data File"},{"name":"Output 6","type":"Raw Data File"},{"name":"Output 7","type":"Raw Data File"},{"name":"Output 8","type":"Raw Data File"},{"name":"Output 9","type":"Raw Data File"}]}],"name":"MyTemplate","description":"","organisation":"Custom Organisation","version":"0.0.0","authors":[{"firstName":"John","lastName":"Doe"},{"firstName":"Jane","lastName":"Doe"}],"endpoint_repositories":[{"annotationValue":"Test"},{"annotationValue":"Testing second"}],"tags":[],"last_updated":"2023-09-21T12:45:46.9449945Z"}
8 changes: 5 additions & 3 deletions src/ARCtrl/ARCtrl.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,15 @@
<Compile Include="Path.fs" />
<Compile Include="FileSystemTree.fs" />
<Compile Include="SemVer.fs" />
<Compile Include="WebRequest\WebRequest.fs" />
<Compile Include="Contracts\Contracts.ArcAssay.fs" />
<Compile Include="Contracts\Contracts.ArcStudy.fs" />
<Compile Include="Contracts\Contracts.ArcInvestigation.fs" />
<Compile Include="Contracts\Contracts.ARCtrl.fs" />
<Compile Include="Templates\Templates.fs" />
<Compile Include="Templates\Templates.Json.fs" />
<Compile Include="Templates\Templates.Spreadsheet.fs" />
<Compile Include="Templates\Template.fs" />
<Compile Include="Templates\Template.Json.fs" />
<Compile Include="Templates\Template.Spreadsheet.fs" />
<Compile Include="Templates\Template.Web.fs" />
<None Include="README.md" />
<Compile Include="ARCtrl.fs" />
</ItemGroup>
Expand Down
Loading