Skip to content

Commit

Permalink
Merge pull request #476 from nfdi4plants/fixes
Browse files Browse the repository at this point in the history
Several small fixes
  • Loading branch information
HLWeil authored Nov 18, 2024
2 parents 30e5a19 + 852686c commit 440a84e
Show file tree
Hide file tree
Showing 8 changed files with 245 additions and 62 deletions.
200 changes: 152 additions & 48 deletions poetry.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ keywords = ["arc", "annotated research context", "isa", "research data", "multi

[tool.poetry.dependencies]
python = "^3.10"
requests = "2.28.1"
requests = ">= 2.28.1, <3.0.0"

[tool.poetry.group.dev.dependencies]
pytest = "^8.1.1"
Expand Down
6 changes: 3 additions & 3 deletions src/Spreadsheet/AnnotationTable/CompositeCell.fs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module ARCtrl.Spreadsheet.CompositeCell
module ARCtrl.Spreadsheet.CompositeCell

open ARCtrl
open ARCtrl.Helper
Expand All @@ -19,8 +19,8 @@ let freeTextFromStringCells (cellValues : array<string>) : CompositeCell =
CompositeCell.createFreeText cellValues.[0]

let dataFromStringCells (format : int option) (selectorFormat : int option) (cellValues : array<string>) : CompositeCell =
let format = Option.map (fun i -> cellValues.[i]) format
let selectorFormat = Option.map (fun i -> cellValues.[i]) selectorFormat
let format = Option.bind (fun i -> cellValues.[i] |> Option.fromValueWithDefault "") format
let selectorFormat = Option.bind (fun i -> cellValues.[i] |> Option.fromValueWithDefault "") selectorFormat
CompositeCell.createDataFromString(cellValues.[0],?format = format, ?selectorFormat = selectorFormat)


Expand Down
8 changes: 2 additions & 6 deletions src/Spreadsheet/AnnotationTable/CompositeColumn.fs
Original file line number Diff line number Diff line change
Expand Up @@ -72,14 +72,10 @@ let toStringCellColumns (column : CompositeColumn) : string list list =
[header.[2]; for i = 0 to column.Cells.Length - 1 do getCellOrDefault i 2 cells]
]
elif isData then
let hasFormat = column.Cells |> Seq.exists (fun c -> c.ToDataCell().AsData.Format.IsSome)
let hasSelectorFormat = column.Cells |> Seq.exists (fun c -> c.ToDataCell().AsData.SelectorFormat.IsSome)
[
[header.[0]; for i = 0 to column.Cells.Length - 1 do getCellOrDefault i 0 cells]
if hasFormat then
[header.[1]; for i = 0 to column.Cells.Length - 1 do getCellOrDefault i 1 cells]
if hasSelectorFormat then
[header.[2]; for i = 0 to column.Cells.Length - 1 do getCellOrDefault i 2 cells]
[header.[1]; for i = 0 to column.Cells.Length - 1 do getCellOrDefault i 1 cells]
[header.[2]; for i = 0 to column.Cells.Length - 1 do getCellOrDefault i 2 cells]
]
else
[
Expand Down
11 changes: 9 additions & 2 deletions src/Spreadsheet/Template.fs
Original file line number Diff line number Diff line change
Expand Up @@ -223,9 +223,16 @@ module Template =
open Metadata
open Template

[<System.Obsolete>]
let [<Literal>] metaDataSheetName = "isa_template"

[<System.Obsolete>]
let [<Literal>] obsoletemetaDataSheetName = "SwateTemplateMetadata"

let metadataSheetName = "isa_template"
let obsoleteMetadataSheetName = "SwateTemplateMetadata"


let fromParts (templateInfo : TemplateInfo) (ers : OntologyAnnotation list) (tags : OntologyAnnotation list) (authors : Person list) (table : ArcTable) (lastUpdated : System.DateTime) =
Template.make
(System.Guid templateInfo.Id)
Expand All @@ -240,7 +247,7 @@ module Template =
lastUpdated

let isMetadataSheetName (name : string) =
name = metaDataSheetName || name = obsoletemetaDataSheetName
name = metadataSheetName || name = obsoleteMetadataSheetName

let isMetadataSheet (sheet : FsWorksheet) =
isMetadataSheetName sheet.Name
Expand All @@ -250,7 +257,7 @@ module Template =
|> Seq.tryFind isMetadataSheet

let toMetadataSheet (template : Template) : FsWorksheet =
let sheet = FsWorksheet(metaDataSheetName)
let sheet = FsWorksheet(metadataSheetName)
Template.toRows template
|> Seq.iteri (fun rowI r -> SparseRow.writeToSheet (rowI + 1) r sheet)
sheet
Expand Down
66 changes: 66 additions & 0 deletions tests/Spreadsheet/ArcTableTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,71 @@ let private ioTable =
)
]

let private ioTable_obsoleteData =
testList "ioTable_obsoleteData" [
let wsName = "MyWorksheet"
let ws_obsoleteData =
initWorksheet wsName
[
Input.appendSampleColumn 1
Protocol.REF.appendLolColumn 1
Parameter.appendTemperatureColumn 1
Characteristic.appendOrganismColumn 1
Factor.appendTimeColumn 1
Output.appendObsoleteDataColumn 1
]
let ws =
initWorksheet wsName
[
Input.appendSampleColumn 1
Protocol.REF.appendLolColumn 1
Parameter.appendTemperatureColumn 1
Characteristic.appendOrganismColumn 1
Factor.appendTimeColumn 1
Output.appendSimpleDataColumn 1
]
testCase "Read" (fun () ->

let table = ArcTable.tryFromFsWorksheet ws_obsoleteData

Expect.isSome table "Table was not created"
let table = table.Value

Expect.equal table.Name wsName "Name did not match"
Expect.equal table.ColumnCount 6 "Wrong number of columns"
Expect.equal table.RowCount 1 "Wrong number of rows"

let expectedHeaders =
[
Input.sampleHeader
Protocol.REF.lolHeader
Parameter.temperatureHeader
Characteristic.organismHeader
Factor.timeHeader
Output.simpleDataHeader
]
Expect.sequenceEqual table.Headers expectedHeaders "Headers did not match"
let expectedCells =
[
Input.sampleValue
Protocol.REF.lolValue
Parameter.temperatureValue
Characteristic.organismValue
Factor.timeValue
Output.simpleDataValue
]
Expect.sequenceEqual (table.GetRow(0)) expectedCells "Cells did not match"
)
testCase "Write" (fun () ->

let table = ArcTable.tryFromFsWorksheet ws_obsoleteData
Expect.isSome table "Table was not created"
let out = ArcTable.toFsWorksheet None table.Value
Expect.workSheetEqual out ws "Worksheet was not correctly written"

)
]

let private fullDataTable =
testList "fullDataTable" [
let wsName = "MyWorksheet"
Expand Down Expand Up @@ -530,6 +595,7 @@ let main =
simpleTable
mixedTable
ioTable
ioTable_obsoleteData
valuelessTable
fullDataTable
commentTable
Expand Down
2 changes: 1 addition & 1 deletion tests/Spreadsheet/Main.fs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module ARCtrl.Spreadsheet.Tests

open Fable.Pyxpecto

let all = testSequenced <| testList "ISA.Spreadsheet" [
let all = testSequenced <| testList "Spreadsheet" [
FableTests.main
RegexTests.main
ArcInvestigationTests.main
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module TestObjects.Spreadsheet.ArcTable
module TestObjects.Spreadsheet.ArcTable

open FsSpreadsheet
open ARCtrl
Expand Down Expand Up @@ -256,11 +256,21 @@ module Output =

let sampleValueV1 = "MySample"

let appendObsoleteDataColumn l (c : FsCellsCollection) (t : FsTable) =
let colCount = if t.IsEmpty(c) then 0 else t.ColumnCount()
t.Cell(FsAddress(1, colCount + 1),c).SetValueAs dataHeaderV1
for i = 2 to l + 1 do
t.Cell(FsAddress(i, colCount + 1),c).SetValueAs dataValueV1

let appendSimpleDataColumn l (c : FsCellsCollection) (t : FsTable) =
let colCount = if t.IsEmpty(c) then 0 else t.ColumnCount()
t.Cell(FsAddress(1, colCount + 1),c).SetValueAs dataHeaderV1
t.Cell(FsAddress(1, colCount + 2),c).SetValueAs dataHeaderV2
t.Cell(FsAddress(1, colCount + 3),c).SetValueAs dataHeaderV3
for i = 2 to l + 1 do
t.Cell(FsAddress(i, colCount + 1),c).SetValueAs dataValueV1
t.Cell(FsAddress(i, colCount + 2),c).SetValueAs ""
t.Cell(FsAddress(i, colCount + 3),c).SetValueAs ""

let appendFullDataColumn l (c : FsCellsCollection) (t : FsTable) =
let colCount = if t.IsEmpty(c) then 0 else t.ColumnCount()
Expand Down

0 comments on commit 440a84e

Please sign in to comment.