Skip to content

Commit

Permalink
Implemented species extraction to JSON and CSV. (#7)
Browse files Browse the repository at this point in the history
  • Loading branch information
Utar94 authored Dec 29, 2023
1 parent 09cc5cf commit 79b8953
Show file tree
Hide file tree
Showing 28 changed files with 737 additions and 2 deletions.
18 changes: 18 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
name: Build PokéData Solution

on:
push:
branches:
- main
workflow_dispatch:

jobs:
build:
name: Build PokéData Solution
runs-on: ubuntu-latest
steps:
- name: Checkout Repository
uses: actions/checkout@v4

- name: Build Docker Image
run: docker build . -t francispion.azurecr.io/pokedata:${{ github.sha }} -f src/PokeData.ETL/Dockerfile
7 changes: 6 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -360,4 +360,9 @@ MigrationBackup/
.ionide/

# Fody - auto-generated XML schema
FodyWeavers.xsd
FodyWeavers.xsd

# Output files
resources.json
species.csv
species.json
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## Unreleased

Nothing yet.
### Added

- Implemented species extraction to JSON and CSV.
12 changes: 12 additions & 0 deletions PokeData.sln
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,19 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
README.md = README.md
EndProjectSection
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PokeData.ETL", "src\PokeData.ETL\PokeData.ETL.csproj", "{FC44EF38-D8A6-4A84-84AB-7597501F54BF}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{FC44EF38-D8A6-4A84-84AB-7597501F54BF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{FC44EF38-D8A6-4A84-84AB-7597501F54BF}.Debug|Any CPU.Build.0 = Debug|Any CPU
{FC44EF38-D8A6-4A84-84AB-7597501F54BF}.Release|Any CPU.ActiveCfg = Release|Any CPU
{FC44EF38-D8A6-4A84-84AB-7597501F54BF}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
Expand Down
23 changes: 23 additions & 0 deletions src/PokeData.ETL/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#See https://aka.ms/customizecontainer to learn how to customize your debug container and how Visual Studio uses this Dockerfile to build your images for faster debugging.

FROM mcr.microsoft.com/dotnet/runtime:8.0 AS base
USER app
WORKDIR /app

FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build
ARG BUILD_CONFIGURATION=Release
WORKDIR /src
COPY ["src/PokeData.ETL/PokeData.ETL.csproj", "src/PokeData.ETL/"]
RUN dotnet restore "./src/PokeData.ETL/./PokeData.ETL.csproj"
COPY . .
WORKDIR "/src/src/PokeData.ETL"
RUN dotnet build "./PokeData.ETL.csproj" -c $BUILD_CONFIGURATION -o /app/build

FROM build AS publish
ARG BUILD_CONFIGURATION=Release
RUN dotnet publish "./PokeData.ETL.csproj" -c $BUILD_CONFIGURATION -o /app/publish /p:UseAppHost=false

FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "PokeData.ETL.dll"]
23 changes: 23 additions & 0 deletions src/PokeData.ETL/Entities/Generation.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using System.Text.Json.Serialization;

namespace PokeData.ETL.Entities;

internal class Generation
{
public int Number { get; set; }

public string UniqueName { get; set; } = string.Empty;
public string? DisplayName { get; set; }

public Region? Region { get; set; }

[JsonIgnore]
public List<PokemonSpecies> Species { get; set; } = [];

public static Generation FromModel(Models.Generation model, string languageName) => new()
{
Number = model.Id,
UniqueName = model.Name,
DisplayName = model.Names.SingleOrDefault(name => name.Language?.Name == languageName)?.Value
};
}
45 changes: 45 additions & 0 deletions src/PokeData.ETL/Entities/PokemonSpecies.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
namespace PokeData.ETL.Entities;

internal class PokemonSpecies
{
public ushort Number { get; set; }
public int Order { get; set; }

public string UniqueName { get; set; } = string.Empty;
public string? DisplayName { get; set; }
public string? Category { get; set; }

public double? GenderRatio { get; set; }
public byte CatchRate { get; set; }

public byte HatchTime { get; set; }

public byte BaseFriendship { get; set; }

public bool IsBaby { get; set; }
public bool IsLegendary { get; set; }
public bool IsMythical { get; set; }
public bool HasGenderDifferences { get; set; }
public bool CanSwitchForm { get; set; }

public Generation? Generation { get; set; }
public List<PokemonVariety> Varieties { get; set; } = [];

public static PokemonSpecies FromModel(Models.PokemonSpecies model, string languageName) => new()
{
Number = (ushort)model.Id,
Order = model.Order,
UniqueName = model.Name,
DisplayName = model.Names.SingleOrDefault(name => name.Language?.Name == languageName)?.Value,
Category = model.Genera.SingleOrDefault(genus => genus.Language?.Name == languageName)?.Value,
GenderRatio = model.GenderRate == -1 ? null : (1 - model.GenderRate / 8.0),
CatchRate = (byte)model.CaptureRate,
HatchTime = (byte?)model.HatchCounter ?? 0,
BaseFriendship = (byte?)model.BaseHappiness ?? 0,
IsBaby = model.IsBaby,
IsLegendary = model.IsLegendary,
IsMythical = model.IsMythical,
HasGenderDifferences = model.HasGenderDifferences,
CanSwitchForm = model.FormsSwitchable
};
}
16 changes: 16 additions & 0 deletions src/PokeData.ETL/Entities/PokemonType.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
namespace PokeData.ETL.Entities;

internal class PokemonType
{
public int Number { get; set; }

public string UniqueName { get; set; } = string.Empty;
public string? DisplayName { get; set; }

public static PokemonType FromModel(Models.Type model, string languageName) => new()
{
Number = model.Id,
UniqueName = model.Name,
DisplayName = model.Names.SingleOrDefault(name => name.Language?.Name == languageName)?.Value
};
}
34 changes: 34 additions & 0 deletions src/PokeData.ETL/Entities/PokemonVariety.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
using System.Text.Json.Serialization;

namespace PokeData.ETL.Entities;

internal class PokemonVariety
{
public int Number { get; set; }
public int Order { get; set; }

public bool IsDefault { get; set; }

public string UniqueName { get; set; } = string.Empty;

public double Height { get; set; }
public double Weight { get; set; }

public ushort BaseExperienceYield { get; set; }

public List<PokemonType> Types { get; set; } = [];

[JsonIgnore]
public PokemonSpecies? Species { get; set; }

public static PokemonVariety FromModel(Models.Pokemon model) => new()
{
Number = model.Id,
Order = model.Order,
IsDefault = model.IsDefault,
UniqueName = model.Name,
Height = model.Height / 10.0,
Weight = model.Weight / 10.0,
BaseExperienceYield = (ushort?)model.BaseExperience ?? 0
};
}
21 changes: 21 additions & 0 deletions src/PokeData.ETL/Entities/Region.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using System.Text.Json.Serialization;

namespace PokeData.ETL.Entities;

internal class Region
{
public int Number { get; set; }

public string UniqueName { get; set; } = string.Empty;
public string? DisplayName { get; set; }

[JsonIgnore]
public Generation? Generation { get; set; }

public static Region FromModel(Models.Region model, string languageName) => new()
{
Number = model.Id,
UniqueName = model.Name,
DisplayName = model.Names.SingleOrDefault(name => name.Language?.Name == languageName)?.Value
};
}
9 changes: 9 additions & 0 deletions src/PokeData.ETL/Models/APIResource.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
using System.Text.Json.Serialization;

namespace PokeData.ETL.Models;

internal record APIResource
{
[JsonPropertyName("url")]
public string Url { get; set; } = string.Empty;
}
25 changes: 25 additions & 0 deletions src/PokeData.ETL/Models/Generation.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using System.Text.Json.Serialization;

namespace PokeData.ETL.Models;

internal record Generation
{
[JsonPropertyName("id")]
public int Id { get; set; }

[JsonPropertyName("name")]
public string Name { get; set; } = string.Empty;

// TODO(fpion): abilities

[JsonPropertyName("names")]
public List<Name> Names { get; set; } = [];

[JsonPropertyName("main_region")]
public NamedAPIResource? MainRegion { get; set; }

// TODO(fpion): moves
// TODO(fpion): pokemon_species
// TODO(fpion): types
// TODO(fpion): version_groups
}
12 changes: 12 additions & 0 deletions src/PokeData.ETL/Models/Genus.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using System.Text.Json.Serialization;

namespace PokeData.ETL.Models;

internal record Genus
{
[JsonPropertyName("genus")]
public string Value { get; set; } = string.Empty;

[JsonPropertyName("language")]
public NamedAPIResource? Language { get; set; }
}
12 changes: 12 additions & 0 deletions src/PokeData.ETL/Models/Name.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using System.Text.Json.Serialization;

namespace PokeData.ETL.Models;

internal record Name
{
[JsonPropertyName("name")]
public string Value { get; set; } = string.Empty;

[JsonPropertyName("language")]
public NamedAPIResource? Language { get; set; }
}
9 changes: 9 additions & 0 deletions src/PokeData.ETL/Models/NamedAPIResource.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
using System.Text.Json.Serialization;

namespace PokeData.ETL.Models;

internal record NamedAPIResource : APIResource
{
[JsonPropertyName("name")]
public string Name { get; set; } = string.Empty;
}
44 changes: 44 additions & 0 deletions src/PokeData.ETL/Models/Pokemon.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
using System.Text.Json.Serialization;

namespace PokeData.ETL.Models;

internal class Pokemon
{
[JsonPropertyName("id")]
public int Id { get; set; }

[JsonPropertyName("name")]
public string Name { get; set; } = string.Empty;

[JsonPropertyName("base_experience")]
public int? BaseExperience { get; set; }

[JsonPropertyName("height")]
public int Height { get; set; }

[JsonPropertyName("is_default")]
public bool IsDefault { get; set; }

[JsonPropertyName("order")]
public int Order { get; set; }

[JsonPropertyName("weight")]
public int Weight { get; set; }

// TODO(fpion): abilities
// TODO(fpion): forms
// TODO(fpion): game_indices
// TODO(fpion): held_items
// TODO(fpion): location_area_encounters
// TODO(fpion): moves
// TODO(fpion): past_types
// TODO(fpion): sprites

[JsonPropertyName("species")]
public NamedAPIResource? Species { get; set; }

// TODO(fpion): stats

[JsonPropertyName("types")]
public List<PokemonType> Types { get; set; } = [];
}
Loading

0 comments on commit 79b8953

Please sign in to comment.