Skip to content

Commit

Permalink
Try the Azure Function API for comments
Browse files Browse the repository at this point in the history
  • Loading branch information
bpmerkel committed Jun 1, 2024
1 parent db87a23 commit 19e0763
Show file tree
Hide file tree
Showing 16 changed files with 583 additions and 181 deletions.
29 changes: 27 additions & 2 deletions Api/Api.csproj
Original file line number Diff line number Diff line change
@@ -1,15 +1,34 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<TargetFramework>net6.0</TargetFramework>
<AzureFunctionsVersion>v4</AzureFunctionsVersion>
<OutputType>Exe</OutputType>
</PropertyGroup>
<ItemGroup>
<None Remove="comments.json" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.Http" Version="3.2.0" />
<PackageReference Include="Microsoft.Azure.Functions.Worker.Sdk" Version="1.17.2" OutputItemType="Analyzer" />
<PackageReference Include="Microsoft.Azure.Functions.Worker" Version="1.22.0" />
</ItemGroup>
<ItemGroup>
<Content Include="comments.csv">
<ExcludeFromSingleFile>true</ExcludeFromSingleFile>
<CopyToPublishDirectory>Never</CopyToPublishDirectory>
</Content>
<Content Include="comments.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
</ItemGroup>
<ItemGroup>
<None Update="comments.tt">
<Generator>TextTemplatingFileGenerator</Generator>
<LastGenOutput>comments.json</LastGenOutput>
<ExcludeFromSingleFile>true</ExcludeFromSingleFile>
<CopyToPublishDirectory>Never</CopyToPublishDirectory>
<CopyToOutputDirectory>Never</CopyToOutputDirectory>
</None>
<None Update="host.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
Expand All @@ -21,4 +40,10 @@
<ItemGroup>
<ProjectReference Include="..\Shared\Shared.csproj" />
</ItemGroup>
<ItemGroup>
<Service Include="{508349b6-6b84-4df5-91f0-309beebad82d}" />
</ItemGroup>
<ItemGroup>
<Using Include="System.Threading.ExecutionContext" Alias="ExecutionContext" />
</ItemGroup>
</Project>
43 changes: 14 additions & 29 deletions Api/CommentDataFunction.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using System;
using System.Diagnostics;
using System.Linq;
using System.IO;
using System.Net;
using System.Text.Json;
using FLLJudge.Shared;
using Microsoft.Azure.Functions.Worker;
using Microsoft.Azure.Functions.Worker.Http;
Expand All @@ -16,9 +16,14 @@ namespace ApiIsolated;
/// Initializes a new instance of the <see cref="HttpTrigger"/> class.
/// </remarks>
/// <param name="loggerFactory">The logger factory.</param>
public class HttpTrigger(ILoggerFactory loggerFactory)
public class CommentDataFunction
{
private readonly ILogger _logger = loggerFactory.CreateLogger<HttpTrigger>();
private readonly ILogger _logger;

public CommentDataFunction(ILoggerFactory loggerFactory)
{
_logger = loggerFactory.CreateLogger<CommentDataFunction>();
}

/// <summary>
/// Runs the HTTP trigger.
Expand All @@ -29,32 +34,12 @@ public class HttpTrigger(ILoggerFactory loggerFactory)
public HttpResponseData Run([HttpTrigger(AuthorizationLevel.Anonymous, "get")] HttpRequestData req)
{
var sw = Stopwatch.StartNew();
var result = Enumerable.Range(1, 5)
.Select(index => new CommentData
{
Date = DateTime.Now.AddDays(index),
Summary = GetSummary(0)
})
.ToArray();

string fileName = "comments.json";
using var fileStream = new FileStream(fileName, FileMode.Open, FileAccess.Read);
var model = JsonSerializer.Deserialize<Model>(fileStream);
var response = req.CreateResponse(HttpStatusCode.OK);
response.WriteAsJsonAsync(result).AsTask().Wait();

_logger.LogMetric("TransactionTimeNS", sw.Elapsed.TotalNanoseconds);
response.WriteAsJsonAsync(model).AsTask().Wait();
_logger.LogMetric("TransactionTimeNS", sw.Elapsed.TotalMilliseconds);
return response;
}

/// <summary>
/// Gets the summary based on the temperature.
/// </summary>
/// <param name="temp">The temperature.</param>
/// <returns>The summary.</returns>
private string GetSummary(int temp) =>
temp switch
{
>= 32 => "Hot",
<= 16 and > 0 => "Cold",
<= 0 => "Freezing",
_ => "Mild",
};
}
53 changes: 53 additions & 0 deletions Api/comments.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
Area,Section,Comment
Core Values,GreatJob,We were impressed with your because ...
Core Values,GreatJob,We really liked the way you ... You should be proud of your work!
Core Values,GreatJob,Good description of applying Core Values as participants in sports
Core Values,GreatJob,Great division of roles - effective use of each other's strengths
Core Values,GreatJob,The team notebook to capture progress toward goals shows good planning
Core Values,GreatJob,The team was good about acknowledging ideas from every one
Core Values,GreatJob,The use of rotating buddy pairs to do both robot and project work shows good Coopertition
Core Values,GreatJob,We liked how you showed us your team meeting agenda including activities for all four aspects of the challenge
Core Values,GreatJob,Your slogan of 'Coaches guide, Kids decide' reflects kids doing the work
Core Values,ThinkAbout,You are making good progress with ... One way you could improve would be ...
Core Values,ThinkAbout,As a next step, consider (or have you considered?) doing ...
Core Values,ThinkAbout,Consider expressing how the team explored new skills and ideas
Core Values,ThinkAbout,Consider expressing how the team used creativity and persistence to solve problems
Core Values,ThinkAbout,Consider expressing how the team applied what they learned to improve their world
Core Values,ThinkAbout,Consider expressing how the team demonstrated respect and embraced their differences
Core Values,ThinkAbout,Consider expressing how the team clearly showed they had worked as a team throughout their journey
Core Values,ThinkAbout,Consider expressing how the team clearly had fun and celebrated what they have achieved - as individuals and a group
Innovation Project,GreatJob,We were impressed with your because ...
Innovation Project,GreatJob,We really liked the way you ... You should be proud of your work!
Innovation Project,GreatJob,We loved the way you talked to the expert about __ and then used their feedback to improve your ideas
Innovation Project,ThinkAbout,You are making good progress with ... One way you could improve would be ...
Innovation Project,ThinkAbout,As a next step, consider (or have you considered?) doing ...
Innovation Project,ThinkAbout,Consider expressing a clear definition of the problem
Innovation Project,ThinkAbout,Consider expressing clear and detailed research from a variety of sources
Innovation Project,ThinkAbout,Consider engaging additional experts in your research
Innovation Project,ThinkAbout,Consider expressing clear evidence of an inclusive selection process
Innovation Project,ThinkAbout,Consider expressing clear evidence of an effective plan
Innovation Project,ThinkAbout,Consider expressing clearly how the team developed an innovative solution
Innovation Project,ThinkAbout,Consider expressing a detailed model or drawing that helps to share the solution
Innovation Project,ThinkAbout,Consider expressing how the team shared their solution with users and professionals
Innovation Project,ThinkAbout,Consider expressing clear evidence of improvements in your solution
Innovation Project,ThinkAbout,Make your presentation more engaging by ___
Innovation Project,ThinkAbout,Consider expressing more clearly your solution and its potential impact on others
Robot Design,GreatJob,We were impressed with your because ...
Robot Design,GreatJob,We really liked the way you ... You should be proud of your work!
Robot Design,GreatJob,Cohesive team strategy and goals
Robot Design,GreatJob,Like the use of comments
Robot Design,GreatJob,Liked the reuse of attachments
Robot Design,GreatJob,Love your use of sensors
Robot Design,GreatJob,Strategy: Easy missions first, location, matrix points
Robot Design,GreatJob,You have a good strategy
Robot Design,GreatJob,Fantastic Robot
Robot Design,GreatJob,Good use of basic design
Robot Design,GreatJob,We like your wire management
Robot Design,ThinkAbout,You are making good progress with ... One way you could improve would be ...
Robot Design,ThinkAbout,As a next step, consider (or have you considered?) doing ...
Robot Design,ThinkAbout,Consider presenting a RDES
Robot Design,ThinkAbout,Consider use of myblocks
Robot Design,ThinkAbout,Consider using EV3Lessons.com
Robot Design,ThinkAbout,Consider using sensors
Robot Design,ThinkAbout,Consider use of a jig
Robot Design,ThinkAbout,Review the challenge document
Loading

0 comments on commit 19e0763

Please sign in to comment.