Skip to content
This repository was archived by the owner on Dec 5, 2024. It is now read-only.

Commit 6108a44

Browse files
Merge pull request #719 from github-for-unity/fixes/metrics-rename
Renaming metrics to indicate the user interaction that caused them
2 parents 211471d + 6c1afe3 commit 6108a44

File tree

20 files changed

+356
-229
lines changed

20 files changed

+356
-229
lines changed

script

src/GitHub.Api/Application/ApplicationManagerBase.cs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ public ITask InitializeRepository()
168168
})
169169
.ThenInUI(() =>
170170
{
171-
TaskManager.Run(UsageTracker.IncrementNumberOfProjectsInitialized);
171+
TaskManager.Run(UsageTracker.IncrementProjectsInitialized);
172172
InitializeUI();
173173
});
174174
return task;
@@ -191,8 +191,6 @@ protected void SetupMetrics(string unityVersion, bool firstRun, Guid instanceId)
191191
{
192192
//Logger.Trace("Setup metrics");
193193

194-
var usagePath = Environment.UserCachePath.Combine(Constants.UsageFile);
195-
196194
string userId = null;
197195
if (UserSettings.Exists(Constants.GuidKey))
198196
{
@@ -212,7 +210,7 @@ protected void SetupMetrics(string unityVersion, bool firstRun, Guid instanceId)
212210
Environment.NodeJsExecutablePath,
213211
Environment.OctorunScriptPath);
214212

215-
UsageTracker = new UsageTracker(metricsService, UserSettings, usagePath, userId, unityVersion, instanceId.ToString());
213+
UsageTracker = new UsageTracker(metricsService, UserSettings, Environment, userId, unityVersion, instanceId.ToString());
216214

217215
if (firstRun)
218216
{

src/GitHub.Api/Git/IRepository.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,5 +75,8 @@ public interface IRepository : IEquatable<IRepository>, IDisposable
7575
ITask RemoteAdd(string remote, string url);
7676
ITask RemoteRemove(string remote);
7777
ITask Push(string remote);
78+
ITask DeleteBranch(string branch, bool force);
79+
ITask CreateBranch(string branch, string baseBranch);
80+
ITask SwitchBranch(string branch);
7881
}
7982
}

src/GitHub.Api/Git/Repository.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,9 @@ public ITask SetupRemote(string remote, string remoteUrl)
122122
public ITask DiscardChanges(GitStatusEntry[] gitStatusEntry) => repositoryManager.DiscardChanges(gitStatusEntry);
123123
public ITask RemoteAdd(string remote, string url) => repositoryManager.RemoteAdd(remote, url);
124124
public ITask RemoteRemove(string remote) => repositoryManager.RemoteRemove(remote);
125+
public ITask DeleteBranch(string branch, bool force) => repositoryManager.DeleteBranch(branch, force);
126+
public ITask CreateBranch(string branch, string baseBranch) => repositoryManager.CreateBranch(branch, baseBranch);
127+
public ITask SwitchBranch(string branch) => repositoryManager.SwitchBranch(branch);
125128

126129
public void CheckAndRaiseEventsIfCacheNewer(CacheType cacheType, CacheUpdateEvent cacheUpdateEvent) => cacheContainer.CheckAndRaiseEventsIfCacheNewer(cacheType, cacheUpdateEvent);
127130

src/GitHub.Api/Git/RepositoryManager.cs

Lines changed: 33 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -330,12 +330,14 @@ public ITask DiscardChanges(GitStatusEntry[] gitStatusEntries)
330330

331331
if (itemsToRevert.Any())
332332
{
333-
task.Then(GitClient.Discard(itemsToRevert));
333+
var next = GitClient.Discard(itemsToRevert);
334+
HookupHandlers(next, true);
335+
task.OnEnd -= HookupEndHandlerWithWatcher;
336+
task.Then(next);
334337
}
335338
}
336339
, () => gitStatusEntries);
337340

338-
339341
return HookupHandlers(task, true);
340342
}
341343

@@ -459,21 +461,37 @@ private ITask HookupHandlers(ITask task, bool filesystemChangesExpected)
459461
}
460462
};
461463

462-
task.Finally(success =>
464+
if (filesystemChangesExpected)
465+
task.OnEnd += HookupEndHandlerWithWatcher;
466+
else
467+
task.OnEnd += HookupEndHandlerWithoutWatcher;
468+
return task;
469+
}
470+
471+
private void HookupEndHandlerWithWatcher(ITask task, bool success, Exception ex)
472+
{
473+
HookupEndHandler(task, true);
474+
}
475+
476+
private void HookupEndHandlerWithoutWatcher(ITask task, bool success, Exception ex)
477+
{
478+
HookupEndHandler(task, false);
479+
}
480+
481+
private void HookupEndHandler(ITask task, bool filesystemChangesExpected)
482+
{
483+
var isExclusive = task.IsChainExclusive();
484+
if (filesystemChangesExpected)
463485
{
464-
if (filesystemChangesExpected)
465-
{
466-
//Logger.Trace("Ended Operation - Enable Watcher");
467-
watcher.Start();
468-
}
486+
//Logger.Trace("Ended Operation - Enable Watcher");
487+
watcher.Start();
488+
}
469489

470-
if (isExclusive)
471-
{
472-
//Logger.Trace("Ended Operation - Clearing Busy Flag");
473-
IsBusy = false;
474-
}
475-
});
476-
return task;
490+
if (isExclusive)
491+
{
492+
//Logger.Trace("Ended Operation - Clearing Busy Flag");
493+
IsBusy = false;
494+
}
477495
}
478496

479497
private string GetCurrentHead()

src/GitHub.Api/Metrics/IUsageTracker.cs

Lines changed: 15 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -4,32 +4,20 @@ public interface IUsageTracker
44
{
55
bool Enabled { get; set; }
66
void IncrementNumberOfStartups();
7-
void IncrementNumberOfCommits();
8-
void IncrementNumberOfFetches();
9-
void IncrementNumberOfPushes();
10-
void IncrementNumberOfPulls();
11-
void IncrementNumberOfAuthentications();
12-
void IncrementNumberOfProjectsInitialized();
13-
void IncrementNumberOfLocalBranchCreations();
14-
void IncrementNumberOfLocalBranchDeletions();
15-
void IncrementNumberOfLocalBranchCheckouts();
16-
void IncrementNumberOfRemoteBranchCheckouts();
17-
}
18-
19-
class NullUsageTracker : IUsageTracker
20-
{
21-
public bool Enabled { get; set; }
22-
public void IncrementNumberOfStartups() { }
23-
public void IncrementNumberOfCommits() { }
24-
public void IncrementNumberOfFetches() { }
25-
public void IncrementNumberOfPushes() { }
26-
public void IncrementNumberOfPulls() { }
27-
public void IncrementNumberOfAuthentications() { }
28-
public void IncrementNumberOfProjectsInitialized() { }
29-
public void IncrementNumberOfLocalBranchCreations() { }
30-
public void IncrementNumberOfLocalBranchDeletions() { }
31-
public void IncrementNumberOfLocalBranchCheckouts() { }
32-
public void IncrementNumberOfRemoteBranchCheckouts() { }
33-
public void SetMetricsService(IMetricsService instance) { }
7+
void IncrementChangesViewButtonCommit();
8+
void IncrementHistoryViewToolbarFetch();
9+
void IncrementHistoryViewToolbarPush();
10+
void IncrementHistoryViewToolbarPull();
11+
void IncrementAuthenticationViewButtonAuthentication();
12+
void IncrementProjectsInitialized();
13+
void IncrementBranchesViewButtonCreateBranch();
14+
void IncrementBranchesViewButtonDeleteBranch();
15+
void IncrementBranchesViewButtonCheckoutLocalBranch();
16+
void IncrementBranchesViewButtonCheckoutRemoteBranch();
17+
void IncrementSettingsViewButtonLfsUnlock();
18+
void IncrementUnityProjectViewContextLfsLock();
19+
void IncrementUnityProjectViewContextLfsUnlock();
20+
void IncrementPublishViewButtonPublish();
21+
void IncrementApplicationMenuMenuItemCommandLine();
3422
}
3523
}

src/GitHub.Api/Metrics/UsageModel.cs

Lines changed: 26 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1-
using System;
1+
using GitHub.Logging;
2+
using System;
23
using System.Collections.Generic;
34
using System.Globalization;
45
using System.Linq;
6+
using System.Text;
57

68
namespace GitHub.Unity
79
{
@@ -15,7 +17,7 @@ public class Usage
1517
public class Dimensions
1618
{
1719
public string Guid { get; set; }
18-
public DateTime Date { get; set; }
20+
public DateTimeOffset Date { get; set; }
1921
public string AppVersion { get; set; }
2022
public string UnityVersion { get; set; }
2123
public string Lang { get; set; }
@@ -25,16 +27,21 @@ public class Dimensions
2527
public class Measures
2628
{
2729
public int NumberOfStartups { get; set; }
28-
public int Commits { get; set; }
29-
public int Fetches { get; set; }
30-
public int Pushes { get; set; }
31-
public int Pulls { get; set; }
3230
public int ProjectsInitialized { get; set; }
33-
public int Authentications { get; set; }
34-
public int LocalBranchCreations { get; set; }
35-
public int LocalBranchDeletion { get; set; }
36-
public int LocalBranchCheckouts { get; set; }
37-
public int RemoteBranchCheckouts { get; set; }
31+
public int ChangesViewButtonCommit { get; set; }
32+
public int HistoryViewToolbarFetch { get; set; }
33+
public int HistoryViewToolbarPush { get; set; }
34+
public int HistoryViewToolbarPull { get; set; }
35+
public int AuthenticationViewButtonAuthentication { get; set; }
36+
public int BranchesViewButtonCreateBranch { get; set; }
37+
public int BranchesViewButtonDeleteBranch { get; set; }
38+
public int BranchesViewButtonCheckoutLocalBranch { get; set; }
39+
public int BranchesViewButtonCheckoutRemoteBranch { get; set; }
40+
public int SettingsViewButtonLfsUnlock { get; set; }
41+
public int UnityProjectViewContextLfsLock { get; set; }
42+
public int UnityProjectViewContextLfsUnlock { get; set; }
43+
public int PublishViewButtonPublish { get; set; }
44+
public int ApplicationMenuMenuItemCommandLine { get; set; }
3845
}
3946

4047
class UsageModel
@@ -49,7 +56,7 @@ public Usage GetCurrentUsage(string appVersion, string unityVersion, string inst
4956
Guard.ArgumentNotNullOrWhiteSpace(appVersion, "appVersion");
5057
Guard.ArgumentNotNullOrWhiteSpace(unityVersion, "unityVersion");
5158

52-
var date = DateTime.UtcNow.Date;
59+
var now = DateTimeOffset.Now;
5360
if (currentUsage == null)
5461
{
5562
currentUsage = Reports
@@ -62,7 +69,7 @@ public Usage GetCurrentUsage(string appVersion, string unityVersion, string inst
6269
{
6370
InstanceId = instanceId,
6471
Dimensions = {
65-
Date = date,
72+
Date = now,
6673
Guid = Guid,
6774
AppVersion = appVersion,
6875
UnityVersion = unityVersion,
@@ -89,7 +96,12 @@ public void RemoveReports(DateTime beforeDate)
8996

9097
class UsageStore
9198
{
92-
public DateTimeOffset LastUpdated { get; set; } = DateTimeOffset.UtcNow;
99+
public DateTimeOffset LastUpdated { get; set; } = DateTimeOffset.Now;
93100
public UsageModel Model { get; set; } = new UsageModel();
101+
102+
public Measures GetCurrentMeasures(string appVersion, string unityVersion, string instanceId)
103+
{
104+
return Model.GetCurrentUsage(appVersion, unityVersion, instanceId).Measures;
105+
}
94106
}
95107
}

0 commit comments

Comments
 (0)