Skip to content

Commit

Permalink
update for use the same API for fetch user's game play data
Browse files Browse the repository at this point in the history
Signed-off-by: Damien Zhao <[email protected]>
  • Loading branch information
zdm65477730 committed Nov 23, 2024
1 parent 765de62 commit 23f43ba
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 23 deletions.
12 changes: 6 additions & 6 deletions Application/include/nx/PlayData.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@ namespace NX {

// PlayEvents are parsed PdmPlayEvents containing only necessary information
struct PlayEvent {
PlayEventType type; // Type of PlayEvent
AccountUid userID; // UserID
TitleID titleID; // TitleID
EventType eventType; // See EventType enum
u64 clockTimestamp; // Time of event
u64 steadyTimestamp; // Steady timestamp (used for calculating duration)
PlayEventType type; // Type of PlayEvent
AccountUid userID; // UserID
TitleID titleID; // TitleID
EventType eventType; // See EventType enum
u64 clockTimestamp; // Time of event
u64 steadyTimestamp; // Steady timestamp (used for calculating duration)
};

// A PlaySession represents a session of play for a game. It contains the start
Expand Down
6 changes: 3 additions & 3 deletions Application/source/Application.ExportJob.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ namespace Main {
// Check if played, and if not move onto next
NX::RecentPlayStatistics * stats = this->app->playdata_->getRecentStatisticsForTitleAndUser(title->titleID(), std::numeric_limits<u64>::min(), std::numeric_limits<u64>::max(), user->ID());
bool recentLaunched = (stats->launches != 0);
delete stats;

// Add title metadata
tJson["name"] = title->name();
Expand Down Expand Up @@ -94,8 +93,9 @@ namespace Main {
bool allLaunched = (stats2->launches != 0);
tJson["summary"]["firstPlayed"] = stats2->firstPlayed;
tJson["summary"]["lastPlayed"] = stats2->lastPlayed;
tJson["summary"]["playtime"] = stats2->playtime;
tJson["summary"]["launches"] = stats2->launches;
tJson["summary"]["playtime"] = stats->playtime;
tJson["summary"]["launches"] = stats->launches;
delete stats;
delete stats2;

// Append title if played at least once
Expand Down
3 changes: 2 additions & 1 deletion Application/source/ui/screen/AdjustPlaytime.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,8 @@ namespace Screen {
}

size_t idx = std::distance(this->adjustments.begin(), it);
NX::PlayStatistics * stats = this->app->playdata()->getStatisticsForUser(title->titleID(), this->app->activeUser()->ID());
NX::RecentPlayStatistics * stats = this->app->playdata()->getRecentStatisticsForTitleAndUser(title->titleID(), std::numeric_limits<u64>::min(), std::numeric_limits<u64>::max(), this->app->activeUser()->ID());
//NX::PlayStatistics * stats = this->app->playdata()->getStatisticsForUser(title->titleID(), this->app->activeUser()->ID());
CustomElm::ListAdjust * l = new CustomElm::ListAdjust(title->name(), Utils::playtimeToPlayedForString(stats->playtime), this->getValueString(this->adjustments[idx].value));
delete stats;

Expand Down
17 changes: 11 additions & 6 deletions Application/source/ui/screen/AllActivity.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,8 @@ namespace Screen {
}

// Get statistics and append adjustment if needed
NX::PlayStatistics * ps = this->app->playdata()->getStatisticsForUser(t[i]->titleID(), this->app->activeUser()->ID());
NX::RecentPlayStatistics *ps = this->app->playdata()->getRecentStatisticsForTitleAndUser(t[i]->titleID(), std::numeric_limits<u64>::min(), std::numeric_limits<u64>::max(), this->app->activeUser()->ID());
NX::PlayStatistics *ps2 = this->app->playdata()->getStatisticsForUser(t[i]->titleID(), this->app->activeUser()->ID());
std::vector<AdjustmentValue>::iterator it = std::find_if(adjustments.begin(), adjustments.end(), [this, t, i](AdjustmentValue val) {
return (val.titleID == t[i]->titleID() && val.userID == this->app->activeUser()->ID());
});
Expand All @@ -141,12 +142,13 @@ namespace Screen {
totalSecs += ps->playtime;
if (ps->launches == 0) {
// Add in dummy data if not launched before (due to adjustment)
ps->firstPlayed = Utils::Time::posixTimestampToPdm(Utils::Time::getTimeT(Utils::Time::getTmForCurrentTime()));
ps->lastPlayed = ps->firstPlayed;
ps2->firstPlayed = Utils::Time::posixTimestampToPdm(Utils::Time::getTimeT(Utils::Time::getTmForCurrentTime()));
ps2->lastPlayed = ps2->firstPlayed;
ps->launches = 1;

if (ps->playtime == 0) {
delete ps;
delete ps2;
continue;
}
}
Expand All @@ -155,8 +157,8 @@ namespace Screen {
SortInfo * si = new SortInfo;
si->name = t[i]->name();
si->titleID = t[i]->titleID();
si->firstPlayed = ps->firstPlayed;
si->lastPlayed = ps->lastPlayed;
si->firstPlayed = ps2->firstPlayed;
si->lastPlayed = ps2->lastPlayed;
si->playtime = ps->playtime;
si->launches = ps->launches;

Expand All @@ -165,7 +167,7 @@ namespace Screen {
la->setImage(t[i]->imgPtr(), t[i]->imgSize());
la->setTitle(t[i]->name());
la->setPlaytime(Utils::playtimeToPlayedForString(ps->playtime));
la->setLeftMuted(Utils::lastPlayedToString(ps->lastPlayed));
la->setLeftMuted(Utils::lastPlayedToString(ps2->lastPlayed));
la->setRightMuted(Utils::launchesToPlayedString(ps->launches));
la->onPress([this, i](){
this->app->setActiveTitle(i);
Expand All @@ -177,6 +179,9 @@ namespace Screen {
la->setMutedColour(this->app->theme()->mutedText());
la->setLineColour(this->app->theme()->mutedLine());
this->list->addElement(la, si);

delete ps;
delete ps2;
}

// Sort the list
Expand Down
17 changes: 10 additions & 7 deletions Application/source/ui/screen/Details.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,8 @@ namespace Screen {

// update sessions
// Get relevant play stats
NX::PlayStatistics * pss = this->app->playdata()->getStatisticsForUser(this->app->activeTitle()->titleID(), this->app->activeUser()->ID());
//NX::PlayStatistics * pss = this->app->playdata()->getStatisticsForUser(this->app->activeTitle()->titleID(), this->app->activeUser()->ID());
NX::RecentPlayStatistics *pss = this->app->playdata()->getRecentStatisticsForTitleAndUser(this->app->activeTitle()->titleID(), std::numeric_limits<u64>::min(), std::numeric_limits<u64>::max(), this->app->activeUser()->ID());
std::vector<NX::PlaySession> stats = this->app->playdata()->getPlaySessionsForUser(this->app->activeTitle()->titleID(), this->app->activeUser()->ID());

t.tm_min = 0;
Expand Down Expand Up @@ -378,7 +379,7 @@ namespace Screen {

// Add percentage of total playtime
std::string str;
double percent = 100 * ((double)playtime / ((ps->playtime == 0 || ps->playtime < playtime) ? playtime : ps->playtime));
double percent = 100 * ((double)playtime / ((pss->playtime == 0 || pss->playtime < playtime) ? playtime : ps->playtime));
percent = Utils::roundToDecimalPlace(percent, 2);
if (percent < 0.01) {
str = "< 0.01%";
Expand Down Expand Up @@ -642,7 +643,8 @@ namespace Screen {

// Get statistics and append adjustment if needed
std::vector<AdjustmentValue> adjustments = this->app->config()->adjustmentValues();
NX::PlayStatistics * ps = this->app->playdata()->getStatisticsForUser(this->app->activeTitle()->titleID(), this->app->activeUser()->ID());
NX::PlayStatistics * pss = this->app->playdata()->getStatisticsForUser(this->app->activeTitle()->titleID(), this->app->activeUser()->ID());
NX::RecentPlayStatistics *ps = this->app->playdata()->getRecentStatisticsForTitleAndUser(this->app->activeTitle()->titleID(), std::numeric_limits<u64>::min(), std::numeric_limits<u64>::max(), this->app->activeUser()->ID());
std::vector<AdjustmentValue>::iterator it = std::find_if(adjustments.begin(), adjustments.end(), [this](AdjustmentValue val) {
return (val.titleID == this->app->activeTitle()->titleID() && val.userID == this->app->activeUser()->ID());
});
Expand All @@ -652,8 +654,8 @@ namespace Screen {

if (ps->launches == 0) {
// Add in dummy data if not launched before (due to adjustment)
ps->firstPlayed = Utils::Time::posixTimestampToPdm(Utils::Time::getTimeT(Utils::Time::getTmForCurrentTime()));
ps->lastPlayed = ps->firstPlayed;
pss->firstPlayed = Utils::Time::posixTimestampToPdm(Utils::Time::getTimeT(Utils::Time::getTmForCurrentTime()));
pss->lastPlayed = pss->firstPlayed;
ps->launches = 1;
}

Expand All @@ -672,15 +674,16 @@ namespace Screen {
this->timeplayed->setX(this->timeplayed->x() - this->timeplayed->w()/2);
this->addElement(this->timeplayed);

this->firstplayed = new Aether::Text(1070, 490, Utils::Time::timestampToString(ps->firstPlayed), 20);
this->firstplayed = new Aether::Text(1070, 490, Utils::Time::timestampToString(pss->firstPlayed), 20);
this->firstplayed->setColour(this->app->theme()->accent());
this->firstplayed->setX(this->firstplayed->x() - this->firstplayed->w()/2);
this->addElement(this->firstplayed);

this->lastplayed = new Aether::Text(1070, 580, Utils::Time::timestampToString(ps->lastPlayed), 20);
this->lastplayed = new Aether::Text(1070, 580, Utils::Time::timestampToString(pss->lastPlayed), 20);
this->lastplayed->setColour(this->app->theme()->accent());
this->lastplayed->setX(this->lastplayed->x() - this->lastplayed->w()/2);
this->addElement(this->lastplayed);
delete pss;
delete ps;

// Show update icon if needbe
Expand Down

0 comments on commit 23f43ba

Please sign in to comment.