{"id":13779136,"url":"https://github.com/DanpowerGruppe/Chia","last_synced_at":"2025-05-11T12:33:01.924Z","repository":{"id":35129042,"uuid":"207311557","full_name":"DanpowerGruppe/Chia","owner":"DanpowerGruppe","description":"Chia is a F# library which contains HelperFunctions for reporting, logging and Azure cloud operations. ","archived":false,"fork":false,"pushed_at":"2023-01-06T15:36:30.000Z","size":63632,"stargazers_count":12,"open_issues_count":31,"forks_count":2,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-04-10T18:12:23.688Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://danpowergruppe.github.io/Chia/","language":"CSS","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/DanpowerGruppe.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-09-09T13:08:37.000Z","updated_at":"2023-02-17T18:21:10.000Z","dependencies_parsed_at":"2023-01-15T14:30:32.171Z","dependency_job_id":null,"html_url":"https://github.com/DanpowerGruppe/Chia","commit_stats":null,"previous_names":[],"tags_count":179,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DanpowerGruppe%2FChia","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DanpowerGruppe%2FChia/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DanpowerGruppe%2FChia/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DanpowerGruppe%2FChia/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/DanpowerGruppe","download_url":"https://codeload.github.com/DanpowerGruppe/Chia/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253497332,"owners_count":21917684,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-03T18:01:01.539Z","updated_at":"2025-05-11T12:32:57.820Z","avatar_url":"https://github.com/DanpowerGruppe.png","language":"CSS","funding_links":[],"categories":["Cloud"],"sub_categories":[],"readme":"# Chia - HelperFunctions for reporting\n\n[![Build Status](https://dev.azure.com/DanpowerEnergyData/Chia/_apis/build/status/DanpowerGruppe.Chia?branchName=master)](https://dev.azure.com/DanpowerEnergyData/Chia/_build/latest?definitionId=4\u0026branchName=master)\n\n## Available Packages:\n\n| Library  | Version |\n| ------------- | ------------- |\n| Chia  | [![nuget - Chia](https://img.shields.io/nuget/v/Chia.svg?colorB=green)](https://www.nuget.org/packages/Chia/) |\n| Chia.Client  | [![nuget - ChiaClient](https://img.shields.io/nuget/v/Chia.Client.svg?colorB=green)](https://www.nuget.org/packages/Chia.Client/)  |\n\nChia contains HelperFunctions for reporting. Chia contains some Azure Storage functions, logging features and some excel utils.\n\n## FileWriter\n\nInitialize your FileWriter instant with `initFileWriter`.\nIf you want to log to ApplicationInsight you have to create a new Application Insight resource in Azure and set your ApplicationInsights key.\n\n```fs\nopen Chia\nopen Shared.Logging\nopen Shared.Config\nopen InitBuilder\nlet devStatus = getDevStatusFromEnv  /// Get your devStatus from you environment variable. For example pass in an environment variable in Fake --\u003e '-e devStatus=Productive\nlet fileWriterConfig =\n    initWriter {\n        devStatus Development\n        companyInitials \"dp\"\n        projectName \"TestChia\"\n        devOption (Azure \"aiKey\")\n```\n\n## Infrastructure\n\nChia now can help you to set up your Azure infrastructure by using Chia on top of Farmer. You simply create a new FileWriter and then Chia will create a fresh Azure storageaccount in your preferred location. Chia will connect to your storage account and you don't need to add you storage account at all.\nHere is an example:\n\n```fs\nopen Chia\nopen Infrastructure\nopen InitWriter\nopen Shared.Config\nopen Shared.Logging\nopen Farmer\nlet devStatus = Development\nlet fileWriterConfig =\n    initWriter {\n        devStatus Development\n        companyInitials \"dp\"\n        projectName \"TestChia\"\n        devOption (Azure \"aiKey\")\nlet azAccount = azConnection fileWriterConfig Location.WestEurope\n```\n\n## Know issues\n\nCurrently Chia doesn't support F# projects which are using TypeProviders. There gonna cause issues with Farmer.\n\n## Log\n\nOnce you set configured your initbuilder you can now log to Application Insight or just to a local file\n\nThere are three many log functions. `logStarting`, `logFinished` and `logCritical`.\n\nThe log function is using categories for clustering events in ApplicationInsights. This will help you to get the most out of the ApplicationInsight dashboard and LogAnalytics.\n\nIf you want to log a information that a process is starting you can use `logStarting` like this:\n\n```fs\nLog.logStarting(\"Starting to get Data\",LocalServer,Get,AzureTable,fileWriterConfig)\n```\n\nIf a process finished as expected use `logFinished`:\n\n```fs\nLog.logFinished(\"Finished receiving Data\",LocalServer,Get,AzureTable,fileWriterConfig)\n```\n\nIf a process crashed unexpected use can track the error message with `logCritical`:\n\n```fs\ntry\n    let trySomething = unsafe ()\nwith\n| exn -\u003e\n    let msg = sprintf  \"Your error message: %s\" exn.Message\n    Log.logCritical (msg,LocalService,LocalServer,Get,AzureTable,exn,fileWriterConfig)\n    failwith msg\n```\n\nThe logger uses following clusters.\n\n```fs\nLog.logStarting(\"UsefullMessage\",Source,Operation,Destination,filewriterInfo)\n```\n\nHere are the implemented descriminated unions:\n\n```fs\ntype Source =\n| LocalService\n| LocalServer\n| AzureFunction\n| AzureInfrastructure\n| PiServer\n| Client\n| SPSCommunication\n\ntype Operation =\n| Upload\n| Download\n| Insert\n| Query\n| Create\n| Delete\n| Calculation\n| Post\n| Get\n| Restart\n| Stop\n\ntype Destination =\n| AzureTable\n| QueueTable\n| BlobTable\n| SqlTable\n| LocalStorage\n| EventHub\n```\n\n## CreateTable\n\nHelper to create a Azure table:\n\nFirst connect to your storage account:\n```fs\nopen Chia.CreateTable\nlet connected =\n    let connection = AzureConnection StorageAccount.storageConnString\n    connection.Connect()\n```\nNow you can create your Azure table like this:\n\n```fs\nlet azureTable = getTable \"TableName\" fileWriterConfigAzure connected\n```\n\n## CreateBlob\n\nHelper to create a Azure blobs:\n\nFirst create your blob container:\n\n```fs\nopen Chia.CreateBlob\nlet containerInfo = {   StorageConnString = StorageConnString = StorageAccount.storageConnString\n                        ContainerName = \"ContainerName\"}\nlet myContainer = getContainer containerInfo\n```\n\nNow you can get a list of all you blobs in the container like this:\n\n```fs\nlet blobItems = getBlobs myContainer\n```\n\n## GetTableEntry\n\nHelper to query a Azure tables:\n\nWith the GetTableEntry module you can easily query Azure Tables.\n\nGet just on single tableValue like this:\n```fs\nlet! value = getValue (request.PartKey, request.RowKey) azureTable\n```\n\nGet all values in a table by using a table mapper.\nFirst you have to define you mapper:\n\n```fs\ntype Mapper = {\n    PartKey : string\n    RowKey : Ids.SortableRowKey\n}\n\nlet mapper (entity : DynamicTableEntity) : Mapper =\n    { PartyKey = entity.PartitionKey\n      RowKey = SortableRowKey entity.RowKey\n\nlet! values = getValues mapper azureTable\n```\n\nYou can also get all values by one rowKey like this:\n\n```fs\nlet valuesByRowKey = getValuesByRowKey rowKey mapper azureTable\n```\n\nIf you want to create more complex queries you can just parse in a TableQuery Filter.\n\nFirst define your filter:\n\n```fs\nlet filter partKey = TableQuery.GenerateFilterCondition(\"PartitionKey\", QueryComparisons.Equal, partKey)\nlet filteredValues partKey = getValuesWithFilter (filter partKey) azureTable\n```\n\n## PostToQueue\n\nYou can use Chia to sent out a AzureQueue message like this:\n\n```fs\nopen Chia.PostToQueue\nopen Chia.CreateTable\n\n\nlet connected =\n    let connection = AzureConnection StorageAccount.storageConnString\n    connection.Connect()\n\n[\u003cLiteral\u003e]\nlet SendMail = \"sendmail-queue\"\n\nlet sendQueue = getQueue connected SendMail fileWriterConfig\n```\n\n## RedisCache\n\nHelper to create or directly query a RedisCache:\n\nTo create or read a Redis values with a Redis Key you first have to create a Redis cache info:\n\n```fs\nlet cacheInfo : RedisCache = {\n    Cache = Redis.cache\n    Key = key\n    FileWriterInfo = fileWriterConfig }\n```\n\nTo deserialze your Redis values to your pass in a System.Text.Json mapper.\nYou also should pass in a task to receive your data. The function tries to find the cache in Redis. If there is no Redis cache it will create a new cache by executing you task. The following example shows how to receive a Plant array directly out of Redis or creates a new cache if theres no existing cache and returns the Plant array.\n\n```fs\nlet! plants = tryGetCachedData JsonSerializer.Parse\u003cPlant[]\u003e cacheInfo getPlants\n```\n\n## EventHub\n\nYou can use Chia to sent out a event to Azure Event Hubs like this:\n\n```fs\nopen Chia.EventHubs\n\nlet eventHubClient = getEventHubClient \"EventHubSASConnectionString\"\n\ntype Data = int\n\nlet data = 100\n\ndo! pushEvent (eventHubClient,data,fileWriterConfigAzure)\ndo! pushSingleEvent (eventHubClient,data,fileWriterConfigAzure)\n\n```\n\n## ExcelUtils\n\nMini Helper to start and ExcelApp using the EPPlus package:\n\nStart your excel app like this:\n\n```fs\nlet excelPackage = startExcelApp ()\n```\n\n## Example for a bigger TableMapper\n\nIf you want to map your data from Azure to your specific domain types you could do it like this.\n\n```fs\nopen Chia.CreateTable\n\ntype Address =\n    { LocationId : Ids.LocationId\n      PostalCode : string\n      StreetNr : int option\n      Additions : string option\n      Street : string option\n      Location : string option\n      Country : string option\n      FedState : string option }\n\nlet mapAddress (entity : DynamicTableEntity) : Address =\n    { LocationId = LocationId (entity.PartitionKey |\u003e int64)\n      PostalCode = entity.RowKey\n      StreetNr = getOptionalIntProperty \"StreetNr\" entity\n      Street = getOptionalStringProperty \"Street\" entity\n      Additions = getOptionalStringProperty \"Additions\" entity\n      Location = getOptionalStringProperty \"Location\" entity\n      Country = getOptionalStringProperty \"Country\" entity\n      FedState = getOptionalStringProperty \"FedState\" entity }\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FDanpowerGruppe%2FChia","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FDanpowerGruppe%2FChia","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FDanpowerGruppe%2FChia/lists"}