Skip to content

Commit

Permalink
fix data missing in year view
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 23f43ba commit 15fbf2b
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 16 deletions.
4 changes: 3 additions & 1 deletion Application/include/utils/Debug.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@
#define DEBUG_HPP

#include <string>
#include <cstdio>
#include <mutex>

//#define ENABLE_DEBUG
#define MAX_LOG_LEN 512

namespace Utils {
extern std::mutex mutex;
void write_log(const std::string& msg);
void write_log(const char *pszFmt, ...);
};

#endif
11 changes: 10 additions & 1 deletion Application/source/nx/PlayData.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -260,12 +260,21 @@ namespace NX {
ret.first.push_back(event);
}
}
Utils::write_log("pdmqryQueryPlayEvent() called, rc=" + std::to_string(rc) + " offset=" + std::to_string(offset) + " total_read=" + std::to_string(total_read));
}

// Free memory allocated to array
delete[] pEvents;

#ifdef ENABLE_DEBUG
for (auto event : ret.first) {
if (event->userID.uid[1] == 0 && event->userID.uid[0] == 0) {
Utils::write_log("offset=%d, event: type=%u titleID=%016llx applet_type: %u clockTimestamp=%llu steadyTimestamp=%llu", offset, event->type, event->titleID, event->eventType, event->clockTimestamp, event->steadyTimestamp);
} else {
Utils::write_log("offset=%d, event: type=%u userID=%016llx_%016llx account_type: %u clockTimestamp=%llu steadyTimestamp=%llu", offset, event->type, event->userID.uid[1], event->userID.uid[0], event->eventType, event->clockTimestamp, event->steadyTimestamp);
}
}
#endif

Utils::write_log("readPlayDataFromPdm() exit");
return ret;
}
Expand Down
16 changes: 9 additions & 7 deletions Application/source/ui/screen/Details.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
#include "utils/Lang.hpp"
#include "ui/element/ListSession.hpp"
#include "utils/Utils.hpp"
#include "utils/Time.hpp"
#include "utils/Debug.hpp"

// Values for summary appearance
#define SUMMARY_BOX_HEIGHT 60
Expand Down Expand Up @@ -268,15 +270,15 @@ namespace Screen {

// update sessions
// Get relevant play stats
//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 = begin;
t.tm_min = 0;
t.tm_sec = 0;
// Minus one second so end time is 11:59pm and not 12:00am next day
unsigned int start_time;
unsigned int end_time;
time_t start_time = 0;
time_t end_time = 0;
switch (this->app->viewPeriod()) {
case ViewPeriod::Day:
t.tm_hour = 0;
Expand All @@ -290,7 +292,7 @@ namespace Screen {
end_time = Utils::Time::getTimeT(Utils::Time::increaseTm(t, 'M')) - 1;
break;
case ViewPeriod::Year:
t.tm_mon = 1;
t.tm_mon = 0;
t.tm_mday = 1;
t.tm_hour = 0;
start_time = Utils::Time::getTimeT(t);
Expand All @@ -303,7 +305,7 @@ namespace Screen {
// Add sessions to list
for (size_t i = 0; i < stats.size(); i++) {
// Only add session if start or end is within the current time period
if (stats[i].startTimestamp > end_time || stats[i].endTimestamp < start_time) {
if (stats[i].startTimestamp > static_cast<u64>(end_time) || stats[i].endTimestamp < static_cast<u64>(start_time)) {
continue;
}

Expand All @@ -321,13 +323,13 @@ namespace Screen {

// If started before range set start as start of range
bool outRange = false;
if (stats[i].startTimestamp < start_time) {
if (stats[i].startTimestamp < static_cast<u64>(start_time)) {
outRange = true;
sTm = Utils::Time::getTm(start_time);
}

// If finished after range set end as end of range
if (stats[i].endTimestamp > end_time) {
if (stats[i].endTimestamp > static_cast<u64>(end_time)) {
outRange = true;
eTm = Utils::Time::getTm(end_time);
}
Expand Down
5 changes: 3 additions & 2 deletions Application/source/ui/screen/RecentActivity.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -237,10 +237,11 @@ namespace Screen {
this->graphSubheading->setX(this->header->x() + (this->header->w() - this->graphSubheading->w())/2);

// update Titles
t = begin;
t.tm_min = 0;
t.tm_sec = 0;
// Minus one second so end time is 11:59pm and not 12:00am next day
unsigned int end_time;
time_t end_time = 0;
switch (this->app->viewPeriod()) {
case ViewPeriod::Day:
t.tm_hour = 0;
Expand All @@ -252,7 +253,7 @@ namespace Screen {
end_time = Utils::Time::getTimeT(Utils::Time::increaseTm(t, 'M')) - 1;
break;
case ViewPeriod::Year:
t.tm_mon = 1;
t.tm_mon = 0;
t.tm_mday = 1;
t.tm_hour = 0;
end_time = Utils::Time::getTimeT(Utils::Time::increaseTm(t, 'Y')) - 1;
Expand Down
18 changes: 13 additions & 5 deletions Application/source/utils/Debug.cpp
Original file line number Diff line number Diff line change
@@ -1,22 +1,30 @@

#include <fstream>
#include <ctime>
#include <cstdarg>
#include "utils/Debug.hpp"

namespace Utils {
std::mutex mutex;
void write_log(const std::string& msg) {
void write_log(const char *pszFmt, ...) {
#ifdef ENABLE_DEBUG
if (NULL == pszFmt || 0 == pszFmt[0]) return;

std::time_t currentTime = std::time(nullptr);
std::tm* time = std::localtime(&currentTime);
char buffer[30];
strftime(buffer, sizeof(buffer), "[%Y-%m-%d %H:%M:%S] ", time);
std::string timestamp(buffer);
char timestamp[30];
strftime(timestamp, sizeof(timestamp), "[%Y-%m-%d %H:%M:%S] ", time);

char logstr[MAX_LOG_LEN] = { 0 };
va_list args;
va_start(args, pszFmt);
snprintf(logstr, MAX_LOG_LEN, pszFmt, args);
va_end(args);

std::lock_guard<std::mutex> lock(Utils::mutex);
std::ofstream file("/switch/NX-Activity-Log/debug.log", std::ios::app);
if (file.is_open()) {
file << timestamp + msg << std::endl;
file << std::string(timestamp) + std::string(logstr) << std::endl;
}
#endif
}
Expand Down

0 comments on commit 15fbf2b

Please sign in to comment.