Skip to content

Commit b67b392

Browse files
authored
Merge pull request #15 from NiceOneFox/develop
Sprint 2
2 parents af1fa7c + cf83ade commit b67b392

25 files changed

+329
-66
lines changed

.github/ISSUE_TEMPLATE/bug_report.md

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
---
2+
name: Bug report
3+
about: Create a report to help us improve
4+
title: ''
5+
labels: ''
6+
assignees: ''
7+
8+
---
9+
10+
**Describe the bug**
11+
A clear and concise description of what the bug is.
12+
13+
**To Reproduce**
14+
Steps to reproduce the behavior:
15+
1. Go to '...'
16+
2. Click on '....'
17+
3. Scroll down to '....'
18+
4. See error
19+
20+
**Expected behavior**
21+
A clear and concise description of what you expected to happen.
22+
23+
**Screenshots**
24+
If applicable, add screenshots to help explain your problem.
25+
26+
**Desktop (please complete the following information):**
27+
- OS: [e.g. iOS]
28+
- Browser [e.g. chrome, safari]
29+
- Version [e.g. 22]
30+
31+
**Smartphone (please complete the following information):**
32+
- Device: [e.g. iPhone6]
33+
- OS: [e.g. iOS8.1]
34+
- Browser [e.g. stock browser, safari]
35+
- Version [e.g. 22]
36+
37+
**Additional context**
38+
Add any other context about the problem here.
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
---
2+
name: Feature request
3+
about: Suggest an idea for this project
4+
title: ''
5+
labels: ''
6+
assignees: ''
7+
8+
---
9+
10+
**Is your feature request related to a problem? Please describe.**
11+
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
12+
13+
**Describe the solution you'd like**
14+
A clear and concise description of what you want to happen.
15+
16+
**Describe alternatives you've considered**
17+
A clear and concise description of any alternative solutions or features you've considered.
18+
19+
**Additional context**
20+
Add any other context or screenshots about the feature request here.

README.md

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,37 @@
1-
# ServiceSimulationSystem
1+
# Service Simulation System (Queueing System)
22

33
Project aim is build service simulation system that has flow of requests which are created by sources. Requests is taken by devices on work, if they are no free devices requests go in buffer, also if new requests haven't come we take requests from buffer.
4+
Type of modeling system is "Special events method" (We move from one event to another simply increasing time).
5+
Special events are:
6+
* arrive of new request,
7+
* time of free device,
8+
* end of modeling.
49

10+
Results of moddeling represented by:
11+
* Modeling time
12+
* Amount of Generated requests
13+
* Amount of Served requests
14+
* Average probability of Maintenance ( P = N served / N total )
15+
* Bandwidth of System ( A = N served / T modeling )
16+
* Probability of Failure ( P failire of request = N declined / N total )
17+
18+
Input parameters:
19+
* Number of Sources
20+
* Number of Devices
21+
* Buffer capacity
22+
* Amount of requests
23+
* Modeling time (max time)
24+
* SimulationType (Type of buffer modeling, FIFO, LIFO etc.)
25+
* Lambda (amount of flow) parameter for Poissonian flow
526

627
## Technologies
728
- ASP .NET 6
829
- C# 10
30+
- AutoMapper
931

1032
## Architecture
1133
N-Layer Web API
1234

1335
## Used Design Patterns
14-
1. Factory Pattern (Concrete implementation chosen by input parameter and provided by IoC)
36+
1. Factory Pattern (Concrete implementation is chosen by input parameter)
1537
2. Dependency Injection (DI)

backend/ServiceSimulation/WebApplication2/Api.csproj renamed to backend/ServiceSimulation/Api/Api.csproj

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,14 @@
77
</PropertyGroup>
88

99
<ItemGroup>
10+
<PackageReference Include="AutoMapper" Version="11.0.1" />
1011
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.3.0" />
1112
</ItemGroup>
1213

1314
<ItemGroup>
1415
<Folder Include="Controllers\" />
15-
<Folder Include="Models\" />
16+
<Folder Include="Entities\" />
17+
<Folder Include="Configuration\" />
1618
</ItemGroup>
1719

1820
<ItemGroup>
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
using Api.Entities;
2+
using AutoMapper;
3+
using Bll.Domain.Entities;
4+
using Bll.Domain.Interfaces;
5+
6+
namespace Api.Configuration;
7+
8+
public class ApiMapperConfigurator
9+
{
10+
private readonly IMapperConfigurationExpression _expression;
11+
public IMapperConfigurationExpression AddConfiguration() => _expression;
12+
13+
public ApiMapperConfigurator(IMapperConfigurationExpression expression)
14+
{
15+
MappingApiResults(expression);
16+
17+
_expression = expression;
18+
}
19+
20+
private void MappingApiResults(IMapperConfigurationExpression expression)
21+
{
22+
expression.CreateMap<(FinalResults, IResults), ApiResults>()
23+
.ForMember(dst => dst.AverageProbabilityOfMaintenance,
24+
opt => opt.MapFrom(src => src.Item1.AverageProbabilityOfMaintenance))
25+
.ForMember(dst => dst.ProbabilityOfFailure,
26+
opt => opt.MapFrom(src => src.Item1.ProbabilityOfFailure))
27+
.ForMember(dst => dst.BandwidthOfSystem,
28+
opt => opt.MapFrom(src => src.Item1.BandwidthOfSystem))
29+
.ForMember(dst => dst.AmountOfGeneratedRequests,
30+
31+
opt => opt.MapFrom(src => src.Item2.AmountOfGeneratedRequests))
32+
.ForMember(dst => dst.AmountOfServedRequest,
33+
opt => opt.MapFrom(src => src.Item2.AmountOfServedRequest))
34+
.ForMember(dst => dst.ModelingTime,
35+
opt => opt.MapFrom(src => src.Item2.ModelingTime));
36+
}
37+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
using AutoMapper;
2+
3+
namespace Api.Configuration;
4+
5+
public static class MapperRegistration
6+
{
7+
public static void AddMapper(this IServiceCollection services)
8+
{
9+
var mapper = new MapperConfiguration(cfg => cfg.AddApi());
10+
11+
services.AddSingleton(mapper.CreateMapper());
12+
}
13+
public static IMapperConfigurationExpression AddApi(this IMapperConfigurationExpression expression)
14+
{
15+
return new ApiMapperConfigurator(expression).AddConfiguration();
16+
}
17+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
using Api.Entities;
2+
using Api.enums;
3+
using AutoMapper;
4+
using Bll.Domain.Entities;
5+
using Bll.Domain.Interfaces;
6+
using Microsoft.AspNetCore.Mvc;
7+
8+
namespace Api.Controllers;
9+
10+
[Route("simulation")]
11+
public class Simulation : Controller
12+
{
13+
private readonly ISimulationService _simulationService;
14+
private readonly ITimeProvider _time;
15+
private readonly IResults _results;
16+
private readonly IResultManager _resultManager;
17+
private readonly IMapper _mapper;
18+
public Simulation(ISimulationService simulationService,
19+
ITimeProvider time,
20+
IResults results,
21+
IResultManager resultManager,
22+
IMapper mapper)
23+
{
24+
_simulationService = simulationService;
25+
_time = time;
26+
_results = results;
27+
_resultManager = resultManager;
28+
_mapper = mapper;
29+
}
30+
31+
[HttpGet("/start")]
32+
public IActionResult Start(InputParameters parameters)
33+
{
34+
_simulationService.StartSimulation(parameters);
35+
var endResultsOfModeling = _resultManager.CalculateResultsOfModeling();
36+
var apiResults = _mapper.Map<ApiResults>((endResultsOfModeling, _results));
37+
38+
return Ok(apiResults);
39+
}
40+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
using Bll.Domain.Entities;
2+
3+
namespace Api.Entities;
4+
5+
public record ApiResults
6+
{
7+
public double ModelingTime { get; init; }
8+
public int AmountOfGeneratedRequests { get; init; }
9+
public int AmountOfServedRequest { get; init; }
10+
public double AverageProbabilityOfMaintenance { get; init; }
11+
public double BandwidthOfSystem { get; init; }
12+
public double ProbabilityOfFailure { get; init; }
13+
}

backend/ServiceSimulation/WebApplication2/Program.cs renamed to backend/ServiceSimulation/Api/Program.cs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
using Api.Configuration;
12
using Bll.Domain.Entities;
23
using Bll.Domain.Factories;
34
using Bll.Domain.Interfaces;
@@ -14,17 +15,21 @@
1415

1516
builder.Services.AddScoped<ITimeProvider, TimeProvider>();
1617
builder.Services.AddScoped<IResults, Bll.Domain.Entities.Results>();
18+
builder.Services.AddScoped<IResultManager, ResultManager>();
19+
builder.Services.AddScoped<IResultManager, ResultManager>();
1720
//builder.Services.AddTransient<IBufferManager, StandardBufferManager>();
1821
builder.Services.AddTransient<IBufferManagerFactory, BufferManagerFactory>();
1922
builder.Services.AddTransient<IDeviceManager, DeviceManager>();
2023
builder.Services.AddTransient<ISourceManager, SourceManager>();
24+
//builder.Services.AddScoped<StandardBufferManager>()
25+
// .AddScoped<IBufferManager, StandardBufferManager>(s => s.GetRequiredService<StandardBufferManager>());
2126

22-
23-
builder.Services.AddScoped<StandardBufferManager>()
24-
.AddScoped<IBufferManager, StandardBufferManager>(s => s.GetService<StandardBufferManager>());
25-
27+
//builder.Services.AddScoped<IBufferManager>(s =>
28+
// ActivatorUtilities.CreateInstance<StandardBufferManager>(s));
2629
#endregion
2730

31+
builder.Services.AddMapper();
32+
2833
var app = builder.Build();
2934

3035
if (app.Environment.IsDevelopment())

0 commit comments

Comments
 (0)