Skip to content

Commit

Permalink
add some queue messages
Browse files Browse the repository at this point in the history
  • Loading branch information
tforkmann committed May 21, 2019
1 parent 0389e83 commit f918d42
Show file tree
Hide file tree
Showing 9 changed files with 87 additions and 39 deletions.
10 changes: 9 additions & 1 deletion src/AzureFunctions/AzureReportingUtils/ExpectoTestSuite.fs
Expand Up @@ -7,6 +7,8 @@ open Microsoft.Extensions.Logging
open GetTableEntry
open CloudTable
open Expecto
open PostToQueue
open Microsoft.WindowsAzure.Storage.Queue
[<FunctionName("ExpectoTestSuite")>]
let Run([<TimerTrigger("0 0 0 1 * *")>] myTimer : TimerInfo, log : ILogger) =
task {
Expand All @@ -20,5 +22,11 @@ let Run([<TimerTrigger("0 0 0 1 * *")>] myTimer : TimerInfo, log : ILogger) =
let result =
testList
|> runTests defaultConfig
log.LogInformation ("Test Success {0}", result)
log.LogInformation ("Test Success {0}", result)
match result with
| 1 ->
let msg = CloudQueueMessage(Newtonsoft.Json.JsonConvert.SerializeObject(weatherData))
do! juniperReportsQueue.AddMessageAsync msg
| _ -> ()

}
31 changes: 22 additions & 9 deletions src/AzureFunctions/AzureReportingUtils/JuniperReports.fs
Expand Up @@ -5,7 +5,6 @@ open Juniper.Ids
open Juniper.HeatPrognose
open Juniper
open Expecto
open FileWriter
let reportInfo =
{ ReportName = "Test"
ReportTime = "Test"
Expand All @@ -32,7 +31,7 @@ let sheetData =
Measures = locationValues }
let testSheetInsert =
let excelPackage = startExcelApp ()
{ ExportedReport = reportInfo
{ ReportInformation = reportInfo
ReportData = Some sheetData
ExcelPackage = Some excelPackage }
let testWorkSheets =
Expand All @@ -53,10 +52,24 @@ let expectoTests (reportData:ReportData) =
[ testCase "Test Sum of measures is bigger or equal 0."
<| fun () -> Expect.isGreaterThanOrEqual sumMeasures 0. "SumData should be bigger than or equal"]

let testReport =
report {
sheetInsert testSheetInsert
testReportData expectoTests
worksheetList testWorkSheets
logSuccess "Finished testReport"
}


open Microsoft.Azure.WebJobs
open FSharp.Control.Tasks.ContextInsensitive
open Microsoft.Extensions.Logging
open TriggerNames

[<FunctionName("JuniperReports")>]

let Run([<QueueTrigger(JuniperReports)>] content:string, log:ILogger) =
task {
let testSheetInsert = Newtonsoft.Json.JsonConvert.DeserializeObject<SheetInsert> content
do!
report {
sheetInsert testSheetInsert
testReportData expectoTests
worksheetList testWorkSheets
logSuccess "Finished testReport"
}
log.LogInformation ("Create TestReport")
}
Expand Up @@ -5,8 +5,4 @@ let EscalationLvlLow = "escalation-lvl-low"
[<Literal>]
let EscalationLvlHigh = "escalation-lvl-high"
[<Literal>]
let Validation = "validation-queue"
[<Literal>]
let Start = "start-queue"
[<Literal>]
let Expand = "expand-queue"
let JuniperReports = "juniper-reports"
8 changes: 3 additions & 5 deletions src/AzureFunctions/AzureReportingUtils/ReportSheet.fs
@@ -1,18 +1,16 @@
module ReportSheet
open Juniper
open FSharp.Control.Tasks.ContextInsensitive

///GET WORKSHEET
let testSheet (sheet : SheetInsert option) =
task {
match sheet with
| Some sheetInsert ->
let exportedReport = sheetInsert.ExportedReport
let reportInformation = sheetInsert.ReportInformation
match sheetInsert.ExcelPackage with
| Some package ->
// NAME WORKSHEET
let wks = package.Workbook.Worksheets
let reportName = sheetInsert.ExportedReport.ReportName
let reportName = sheetInsert.ReportInformation.ReportName
let testSheet = wks.Add reportName

let measures =
Expand All @@ -30,7 +28,7 @@ let testSheet (sheet : SheetInsert option) =
testSheet.Cells.[startRow + i, 1].Value <- x.Time |> getNiceDateString
testSheet.Cells.[startRow + i, 2].Value <- x.Value
testSheet.Cells.[startRow + i, 3].Value <- x.UnitOfMeasure)
printfn "Generated %s %s" reportName (matchReportIntervall exportedReport.ReportIntervall)
printfn "Generated %s %s" reportName (matchReportIntervall reportInformation.ReportIntervall)
| None ->
printfn "no excelPackage init"
failwith "no excelPackage init"
Expand Down
2 changes: 1 addition & 1 deletion src/Juniper/Domain.fs
Expand Up @@ -67,7 +67,7 @@ module ReportPipeLine =
Measures : HeatPrognose.Measure [] }

type SheetInsert =
{ ExportedReport : XLSReport
{ ReportInformation : XLSReport
ExcelPackage : ExcelPackage option
ReportData : SheetData option }

Expand Down
2 changes: 1 addition & 1 deletion src/Juniper/Reporting/ExcelUtils.fs
Expand Up @@ -67,7 +67,7 @@ module ExcelUtils =
try
let exportDir = @".\reports\"
let dateTime = DateTime.Now.ToString("yyyyMMdd_HHmm")
let reportPath = Path.Combine(exportDir + "/" + sheetInsert.ExportedReport.ReportName + "_" + dateTime + ".xlsx")
let reportPath = Path.Combine(exportDir + "/" + sheetInsert.ReportInformation.ReportName + "_" + dateTime + ".xlsx")
let data = package.GetAsByteArray()
File.WriteAllBytes(reportPath, data)
printfn "Saving Excel report at %A" reportPath
Expand Down
3 changes: 2 additions & 1 deletion tests/JuniperTest.fsproj
Expand Up @@ -5,11 +5,12 @@
<TargetFramework>netcoreapp2.2</TargetFramework>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include=".\..\scr\Juniper.fsproj">
<ProjectReference Include="../src/Juniper/Juniper.fsproj">
<Name>Juniper.fsproj</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<Compile Include="TestSheet.fs" />
<Compile Include="JuniperTests.fs" />
<Compile Include="Program.fs" />
</ItemGroup>
Expand Down
24 changes: 8 additions & 16 deletions tests/JuniperTests.fs
Expand Up @@ -2,6 +2,8 @@ module JuniperTests

open System
open Juniper
open Juniper.HeatPrognose
open Juniper.Ids
open Expecto
open FileWriter
let reportInfo =
Expand All @@ -11,11 +13,9 @@ let reportInfo =
ReportTyp = "Test"
ReportID = ReportId 1 }
let testLocation =
[| { Description = "Test1"
[| { Name = "Test1"
LocationId = LocationId 1
PostalCode = None
Street = None
Location = Some "TestLocation" }|]
PostalCode = None }|]
let locationValues =
[|
{ Value = 0.
Expand All @@ -32,12 +32,12 @@ let sheetData =
Measures = locationValues }
let testSheetInsert =
let excelPackage = startExcelApp ()
{ ExportedReport = reportInfo
{ ReportInformation = reportInfo
ReportData = Some sheetData
ExcelPackage = Some excelPackage }
let testWorkSheets =
printfn "testWorksheet"
[ ReportSheet.testSheet, "TestWorksheet" ]
[ TestSheet.testSheet, "TestWorksheet" ]

let expectoTests (reportData:ReportData) =
let sheetInsert =
Expand All @@ -54,17 +54,9 @@ let expectoTests (reportData:ReportData) =
<| fun () -> Expect.isGreaterThanOrEqual sumMeasures 0. "SumData should be bigger than or equal"]

let testReport =
// try
report {
sheetInsert testSheetInsert
testReportData expectoTests
worksheetList testWorkSheets
logSuccess "Finished QuarterlyReportExternal"
}
// with exn ->
// let msg =
// sprintf "Can't excecute Async ReportBuilding. %sMessage: %s.%sInnerMessage: %s" Environment.NewLine exn.Message Environment.NewLine
// exn.InnerException.Message
// logError exn msg
// printfn "%s" msg
// failwith msg
logSuccess "Finished TestReport"
}
40 changes: 40 additions & 0 deletions tests/TestSheet.fs
@@ -0,0 +1,40 @@
module TestSheet
open Juniper
open FSharp.Control.Tasks.ContextInsensitive

///GET WORKSHEET
let testSheet (sheet : SheetInsert option) =
task {
match sheet with
| Some sheetInsert ->
let reportInformation = sheetInsert.ReportInformation
match sheetInsert.ExcelPackage with
| Some package ->
// NAME WORKSHEET
let wks = package.Workbook.Worksheets
let reportName = sheetInsert.ReportInformation.ReportName
let testSheet = wks.Add reportName

let measures =
match sheetInsert.ReportData with
| Some reportData -> reportData.Measures
| None -> [||]
// REPORT HEADER
reportHeader reportName measures testSheet
// DEFINING STARTROWS AND STARTCOLOUMS
let startRow = 9
if measures <> [||] then
measures
|> Array.sortBy (fun x -> x.Time)
|> Array.Parallel.iteri (fun i x ->
testSheet.Cells.[startRow + i, 1].Value <- x.Time |> getNiceDateString
testSheet.Cells.[startRow + i, 2].Value <- x.Value
testSheet.Cells.[startRow + i, 3].Value <- x.UnitOfMeasure)
printfn "Generated %s %s" reportName (matchReportIntervall reportInformation.ReportIntervall)
| None ->
printfn "no excelPackage init"
failwith "no excelPackage init"
| None ->
printfn "no SheetData"
failwith "no SheetData"
}

0 comments on commit f918d42

Please sign in to comment.