-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTaskDevelopment.cs
More file actions
132 lines (120 loc) · 5.66 KB
/
Copy pathTaskDevelopment.cs
File metadata and controls
132 lines (120 loc) · 5.66 KB
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using TaskScheduler.Models;
namespace TaskScheduler
{
public class TaskDevelopment : TaskBase
{
private int _Count;
public TaskDevelopment(Manager taskManager) :
base(taskManager, typeof(TaskDevelopment), "Development task", 1, 0, 0)
{
_Count = 0;
Details = _Count.ToString();
}
protected override void ServiceMethod()
{
try
{
//buildFoundRankings();
//addMacroDataTables();
//updatePublisheddate();
//clearQueue();
//updatePublisheddate2();
}
catch (Exception e)
{
Details = e.Message;
}
}
private void buildFoundRankings()
{
using (var db = GCEuDataSupport.Instance.GetGCEuDataDatabase())
{
db.CommandTimeout = 180;
db.Execute("truncate table GCEuFoundsRanking");
var countries = new int[] { 141, 4, 8};
for (int i = 2001; i < 2016; i++)
{
foreach (var c in countries)
{
db.Execute("insert into GCEuFoundsRanking (GCComUserID, Ranking, RankYear, CountryID, Founds) select b.FinderId as GCComUserID, ROW_NUMBER() OVER (order by b.Founds desc, FinderId desc) as Ranking, RankYear=@0, CountryID=@1, b.Founds from (select FinderId, count(1) as Founds from GCComData.dbo.GCComGeocacheLog with (nolock) inner join GCComData.dbo.GCComGeocache with (nolock) on GCComGeocacheLog.CacheCode=GCComGeocache.Code where YEAR(VisitDate)=@2 and WptLogTypeId in (2, 10, 11) and GCComGeocache.CountryID=@3 group by finderid) as b", i, c, i, c);
}
}
foreach (var c in countries)
{
db.Execute("insert into GCEuFoundsRanking (GCComUserID, Ranking, RankYear, CountryID, Founds) select b.FinderId as GCComUserID, ROW_NUMBER() OVER (order by b.Founds desc, FinderId desc) as Ranking, RankYear=0, CountryID=@0, b.Founds from (select FinderId, count(1) as Founds from GCComData.dbo.GCComGeocacheLog with (nolock) inner join GCComData.dbo.GCComGeocache with (nolock) on GCComGeocacheLog.CacheCode=GCComGeocache.Code where WptLogTypeId in (2, 10, 11) and GCComGeocache.CountryID=@1 group by finderid) as b", c, c);
}
}
}
private void addMacroDataTables()
{
using (var db = GCEuDataSupport.Instance.GetGCEuDataDatabase())
{
var tbil = db.Fetch<string>("select TableName from GCEuMacroData.dbo.TableCreationInfo");
var tables = db.Fetch<string>("SELECT name FROM GCEuMacroData.sys.tables WHERE name like 'macro_%' or name like 'LiveAPIDownload_%'");
foreach (var t in tables)
{
if (!tbil.Contains(t))
{
db.Execute("insert into GCEuMacroData.dbo.TableCreationInfo (TableName, Created) values (@0, @1)", t, DateTime.Now);
}
}
}
}
private void clearQueue()
{
using (var db = TaskManager.TaskSchedulerDatabase)
{
db.Execute("truncate table ScheduledWaypoint");
}
}
private void updatePublisheddate()
{
using (var dbEU = GCEuDataSupport.Instance.GetGCEuDataDatabase())
using (var dbCom = GCComDataSupport.Instance.GetGCComDataDatabase())
{
List<GCEuGeocache> gcEUCaches = dbEU.Fetch<GCEuGeocache>("where PublishedAtDate is NULL");
foreach (var gc in gcEUCaches)
{
DateTime? publishedDate = null;
var l = dbCom.FirstOrDefault<GCComGeocacheLog>("where GeocacheID=@0 and WptLogTypeId=24", gc.ID);
if (l != null)
{
publishedDate = l.VisitDate;
}
else
{
publishedDate = dbCom.ExecuteScalar<DateTime>("select UTCPlaceDate from GCComGeocache where ID=@0", gc.ID);
}
dbEU.Execute("update GCEuGeocache set PublishedAtDate=@0 where ID=@1", publishedDate, gc.ID);
_Count++;
Details = _Count.ToString();
}
}
}
private void updatePublisheddate2()
{
using (var dbEU = GCEuDataSupport.Instance.GetGCEuDataDatabase())
using (var dbCom = GCComDataSupport.Instance.GetGCComDataDatabase())
{
List<long> gcEUCaches = dbEU.Fetch<long>("select GCEuGeocache.ID from GCEuGeocache inner join GCComData.dbo.GCComGeocache on GCEuGeocache.ID = GCComGeocache.ID where GCEuGeocache.PublishedAtDate = GCComGeocache.UTCPlaceDate and GCEuGeocache.PublishedAtDate>'2016-03-01'");
foreach (var gc in gcEUCaches)
{
DateTime? publishedDate = null;
var l = dbCom.FirstOrDefault<GCComGeocacheLog>("where GeocacheID=@0 and WptLogTypeId=24", gc);
if (l != null)
{
publishedDate = l.VisitDate;
dbEU.Execute("update GCEuGeocache set PublishedAtDate=@0 where ID=@1", publishedDate, gc);
}
_Count++;
Details = _Count.ToString();
}
}
}
}
}