Skip to content
This repository has been archived by the owner on Apr 12, 2023. It is now read-only.

Feature/export exposure data #931

Merged
8 commits merged into from
May 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Covid19Radar/Covid19Radar/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@ private static void RegisterCommonTypes(IContainer container)
container.Register<ITermsUpdateService, TermsUpdateService>(Reuse.Singleton);
container.Register<IHttpClientService, HttpClientService>(Reuse.Singleton);
container.Register<IMigrationService, MigrationService>(Reuse.Singleton);
container.Register<IExposureDataExportService, ExposureDataExportService>(Reuse.Singleton);

#if USE_MOCK
container.Register<IHttpDataService, HttpDataServiceMock>(Reuse.Singleton);
Expand Down
68 changes: 68 additions & 0 deletions Covid19Radar/Covid19Radar/Model/ExposureData.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at https://mozilla.org/MPL/2.0/.

using System.Collections.Generic;
using Chino;
using Newtonsoft.Json;

namespace Covid19Radar.Model
{
public class ExposureData
{
[JsonProperty("platform")]
public readonly string Platform;

[JsonProperty("platform_version")]
public readonly string PlatformVersion;

[JsonProperty("model")]
public readonly string Model;

[JsonProperty("device_type")]
public readonly string DeviceType;

[JsonProperty("app_version")]
public readonly string AppVersion;

[JsonProperty("build_number")]
public readonly string BuildNumber;

[JsonProperty("en_version")]
public readonly string EnVersion;

[JsonProperty("daily_summaries")]
public readonly List<DailySummary> DailySummaryList;

[JsonProperty("exposure_windows")]
public readonly List<ExposureWindow> ExposureWindowList;

[JsonProperty("exposure_configuration")]
public readonly ExposureConfiguration ExposureConfiguration;

public ExposureData(
string platform,
string platformVersion,
string model,
string deviceType,
string appVersion,
string buildNumber,
string enVersion,
List<DailySummary> dailySummaryList,
List<ExposureWindow> exposureWindowList,
ExposureConfiguration exposureConfiguration
)
{
Platform = platform;
PlatformVersion = platformVersion;
Model = model;
DeviceType = deviceType;
AppVersion = appVersion;
BuildNumber = buildNumber;
EnVersion = enVersion;
DailySummaryList = dailySummaryList;
ExposureWindowList = exposureWindowList;
ExposureConfiguration = exposureConfiguration;
}
}
}
6 changes: 6 additions & 0 deletions Covid19Radar/Covid19Radar/Resources/AppResources.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions Covid19Radar/Covid19Radar/Resources/AppResources.ja.resx
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,10 @@
<value>行動圏内には、陽性登録者はいなかったようです。引き続き感染予防に留意しながらお過ごしください。</value>
<comment>行動圏内には、陽性登録者はいなかったようです。引き続き感染予防に留意しながらお過ごしください。</comment>
</data>
<data name="ExportExposureData" xml:space="preserve">
<value>情報を保存</value>
<comment>情報を保存</comment>
</data>
<data name="TutorialPage3Title" xml:space="preserve">
<value>利用規約</value>
<comment>利用規約</comment>
Expand Down
4 changes: 4 additions & 0 deletions Covid19Radar/Covid19Radar/Resources/AppResources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -436,6 +436,10 @@
<value>It appears there have been no persons who have registered positive for COVID-19 within your sphere of activities. Please continue to pay attention to preventing COVID-19 infections.</value>
<comment>行動圏内には、陽性登録者はいなかったようです。引き続き感染予防に留意しながらお過ごしください。</comment>
</data>
<data name="ExportExposureData" xml:space="preserve">
<value>Save</value>
<comment>TODO:情報を保存</comment>
</data>
<data name="TutorialPage3Title" xml:space="preserve">
<value>Terms of use</value>
<comment>利用規約</comment>
Expand Down
4 changes: 4 additions & 0 deletions Covid19Radar/Covid19Radar/Resources/AppResources.zh-Hans.resx
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,10 @@
<value>您的行动范围内似乎没有阳性登记者。请继续注意防止感染。</value>
<comment>行動圏内には、陽性登録者はいなかったようです。引き続き感染予防に留意しながらお過ごしください。</comment>
</data>
<data name="ExportExposureData" xml:space="preserve">
<value>Save</value>
<comment>TODO:情報を保存</comment>
</data>
<data name="TutorialPage3Title" xml:space="preserve">
<value>使用条款</value>
<comment>利用規約</comment>
Expand Down
61 changes: 0 additions & 61 deletions Covid19Radar/Covid19Radar/Services/EventLogService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -205,65 +205,4 @@ ExposureData exposureData
}
}
#endif

public class ExposureData
{
private string _device = "unknown_device";

[JsonProperty("device")]
public string Device
{
get
{
return _device;
}
set
{
string device = value.Replace(" ", "_");
_device = device;
}
}

[JsonProperty("en_version")]
public string? EnVersion;

[JsonProperty("exposure_summary")]
public readonly ExposureSummary? exposureSummary;

[JsonProperty("exposure_informations")]
public readonly IList<ExposureInformation>? exposureInformations;

[JsonProperty("daily_summaries")]
public readonly IList<DailySummary>? dailySummaries;

[JsonProperty("exposure_windows")]
public readonly IList<ExposureWindow>? exposureWindows;

[JsonProperty("exposure_configuration")]
public readonly ExposureConfiguration exposureConfiguration;

public ExposureData(ExposureConfiguration exposureConfiguration)
: this(exposureConfiguration, null, null, null, null) { }

public ExposureData(ExposureConfiguration exposureConfiguration,
ExposureSummary exposureSummary, IList<ExposureInformation> exposureInformations)
: this(exposureConfiguration, exposureSummary, exposureInformations, null, null) { }

public ExposureData(ExposureConfiguration exposureConfiguration,
IList<DailySummary> dailySummaries, IList<ExposureWindow> exposureWindows)
: this(exposureConfiguration, null, null, dailySummaries, exposureWindows) { }

public ExposureData(ExposureConfiguration exposureConfiguration,
ExposureSummary? exposureSummary, IList<ExposureInformation>? exposureInformations,
IList<DailySummary>? dailySummaries, IList<ExposureWindow>? exposureWindows)
{
this.exposureConfiguration = exposureConfiguration;
this.exposureSummary = exposureSummary;
this.exposureInformations = exposureInformations;
this.dailySummaries = dailySummaries;
this.exposureWindows = exposureWindows;
}

public string ToJsonString() => JsonConvert.SerializeObject(this, Formatting.Indented);
}
}
81 changes: 81 additions & 0 deletions Covid19Radar/Covid19Radar/Services/ExposureDataExportService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at https://mozilla.org/MPL/2.0/.

using System.Collections.Generic;
using System.IO;
using System.Threading.Tasks;
using Chino;
using Covid19Radar.Model;
using Covid19Radar.Repository;
using Covid19Radar.Services.Logs;
using Newtonsoft.Json;

namespace Covid19Radar.Services
{
public interface IExposureDataExportService
{
Task ExportAsync(string path);
}

public class ExposureDataExportService : IExposureDataExportService
{
private readonly ILoggerService _loggerService;

private readonly IExposureDataRepository _exposureDataRepository;

private readonly IExposureConfigurationRepository _exposureConfigurationRepository;
private readonly AbsExposureNotificationApiService _exposureNotificationApiService;

private readonly IEssentialsService _essentialsService;

public ExposureDataExportService(
ILoggerService loggerService,
IExposureDataRepository exposureDataRepository,
IExposureConfigurationRepository exposureConfigurationRepository,
AbsExposureNotificationApiService exposureNotificationApiService,
IEssentialsService essentialsService
)
{
_loggerService = loggerService;
_exposureDataRepository = exposureDataRepository;
_exposureConfigurationRepository = exposureConfigurationRepository;
_exposureNotificationApiService = exposureNotificationApiService;
_essentialsService = essentialsService;
}

public async Task ExportAsync(string filePath)
{
_loggerService.StartMethod();

try
{
long enVersion = await _exposureNotificationApiService.GetVersionAsync();
List<DailySummary> dailySummaryList = await _exposureDataRepository.GetDailySummariesAsync();
List<ExposureWindow> exposureWindowList = await _exposureDataRepository.GetExposureWindowsAsync();
ExposureConfiguration exposureConfiguration = await _exposureConfigurationRepository.GetExposureConfigurationAsync();

var exposureData = new ExposureData(
_essentialsService.Platform,
_essentialsService.PlatformVersion,
_essentialsService.Model,
_essentialsService.DeviceType,
_essentialsService.AppVersion,
_essentialsService.BuildNumber,
enVersion.ToString(),
dailySummaryList,
exposureWindowList,
exposureConfiguration
);

string exposureDataJson = JsonConvert.SerializeObject(exposureData, Formatting.Indented);

await File.WriteAllTextAsync(filePath, exposureDataJson);
}
finally
{
_loggerService.EndMethod();
}
}
}
}
4 changes: 4 additions & 0 deletions Covid19Radar/Covid19Radar/Services/ILocalPathService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ public interface ILocalPathService
private const string CURRENT_EXPOSURE_CONFIGURATION_FILENAME = "exposure_configuration_current.json";
private const string CURRENT_EXPOSURE_RISK_CALCULATION_CONFIGURATION_FILENAME = "exposure_risk_calculation_configuration_current.json";

private const string EXPOSURE_DATA_FILENAME = "exposure_data.json";

string ExposureConfigurationDirPath =>
Path.Combine(FileSystem.AppDataDirectory, EXPOSURE_CONFIGURATION_DIR);

Expand All @@ -25,6 +27,8 @@ public interface ILocalPathService
string CacheDirectory =>
FileSystem.CacheDirectory;

string ExposureDataPath => Path.Combine(CacheDirectory, EXPOSURE_DATA_FILENAME);

string LogsDirPath { get; }
string LogUploadingTmpPath { get; }
string LogUploadingPublicPath { get; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
using Threshold = Covid19Radar.Model.V1ExposureRiskCalculationConfiguration.Threshold;
using Covid19Radar.Services;
using System.Threading.Tasks;
using Xamarin.Essentials;

namespace Covid19Radar.ViewModels
{
Expand All @@ -28,6 +29,8 @@ public class ExposureCheckPageViewModel : ViewModelBase
private readonly IExposureDataRepository _exposureDataRepository;
private readonly IExposureRiskCalculationConfigurationRepository _exposureRiskCalculationConfigurationRepository;
private readonly IExposureRiskCalculationService _exposureRiskCalculationService;
private readonly ILocalPathService _localPathService;
private readonly IExposureDataExportService _exposureDataExportService;
private readonly IUserDataRepository _userDataRepository;
private readonly IDateTimeUtility _dateTimeUtility;

Expand Down Expand Up @@ -61,6 +64,8 @@ public ExposureCheckPageViewModel(
ILoggerService loggerService,
IExposureDataRepository exposureDataRepository,
IExposureRiskCalculationService exposureRiskCalculationService,
ILocalPathService localPathService,
IExposureDataExportService exposureDataExportService,
IUserDataRepository userDataRepository,
IExposureRiskCalculationConfigurationRepository exposureRiskCalculationConfigurationRepository,
IDateTimeUtility dateTimeUtility
Expand All @@ -69,6 +74,8 @@ IDateTimeUtility dateTimeUtility
_loggerService = loggerService;
_exposureDataRepository = exposureDataRepository;
_exposureRiskCalculationService = exposureRiskCalculationService;
_localPathService = localPathService;
_exposureDataExportService = exposureDataExportService;
_userDataRepository = userDataRepository;
_exposureRiskCalculationConfigurationRepository = exposureRiskCalculationConfigurationRepository;
_dateTimeUtility = dateTimeUtility;
Expand Down Expand Up @@ -315,13 +322,28 @@ private ExposureCheckScoreModel CreateExposureCheckScoreModel(DailySummary daily
return exposureCheckModel;
}

public Command OnClickShareApp => new Command(() =>
public Command OnClickExportExposureData => new Command(async () =>
{
_loggerService.StartMethod();

AppUtils.PopUpShare();
try
{
string exposureDataFilePath = _localPathService.ExposureDataPath;
await _exposureDataExportService.ExportAsync(exposureDataFilePath);

_loggerService.EndMethod();
await Share.RequestAsync(new ShareFileRequest
{
File = new ShareFile(exposureDataFilePath)
});
}
catch (NotImplementedInReferenceAssemblyException exception)
{
_loggerService.Exception("NotImplementedInReferenceAssemblyException", exception);
}
finally
{
_loggerService.EndMethod();
}
});
}

Expand Down
Loading