-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathDataImporter.cs
73 lines (64 loc) · 2.45 KB
/
DataImporter.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
using System;
using Microsoft.EntityFrameworkCore;
using System.Collections.Generic;
using System.Linq;
using System.Collections.Concurrent;
using System.Diagnostics;
using Z.EntityFramework.Extensions;
namespace portaBLe
{
public static class DataImporter
{
public static void ImportJsonData(RootObject rootObject, AppContext dbContext)
{
dbContext.ChangeTracker.AutoDetectChangesEnabled = false;
// Disable WAL
dbContext.Database.ExecuteSql($"PRAGMA journal_mode=OFF;");
dbContext.Database.ExecuteSql($"PRAGMA synchronous=OFF;");
foreach (var item in rootObject.Maps)
{
if (item.ModifiersRating != null) {
item.ModifiersRating.Id = 0;
}
}
var leaderboards = rootObject.Maps.Select(map => new Leaderboard
{
Id = map.Id,
Name = map.Name,
Hash = map.Hash,
SongId = map.SongId,
ModeName = map.ModeName,
DifficultyName = map.DifficultyName,
PassRating = map.PassRating,
AccRating = map.AccRating,
TechRating = map.TechRating,
PredictedAcc = map.PredictedAcc,
ModifiersRating = map.ModifiersRating,
Cover = map.CoverImage,
Mapper = map.Mapper,
Stars = ReplayUtils.ToStars(map.AccRating, map.PassRating, map.TechRating)
});
dbContext.Leaderboards.BulkInsertOptimized(leaderboards, options => options.IncludeGraph = true);
var players = rootObject.Players.Select(player => new Player
{
Id = player.Id,
Name = player.Name,
Country = player.Country,
Avatar = player.Avatar,
});
dbContext.Players.BulkInsertOptimized(players);
var scores = rootObject.Scores.Select(score => new Score
{
Id = score.Id,
PlayerId = score.PlayerId,
Timepost = score.Timepost,
LeaderboardId = score.LeaderboardId,
Accuracy = score.Accuracy,
Modifiers = score.Modifiers,
FC = score.FC,
FCAcc = score.FCAcc
});
dbContext.Scores.BulkInsertOptimized(scores);
}
}
}