fix project 2 bugz

This commit is contained in:
Riley S 2021-04-18 16:02:33 -04:00
parent 1570e9f069
commit 1a4a72ecdd
2 changed files with 15 additions and 4 deletions

View File

@ -16,6 +16,8 @@
using json = nlohmann::json;
std::mutex metrics_mutex {};
auto onClientConnected(networked& client)
{
sscout << "Accepted Client on Server.\n";
@ -77,6 +79,7 @@ auto execute_as_client(std::string ipaddress, std::uint16_t port)
net_client.message_received += [&](std::string& message)
{
auto elapsed = clock.elapsed<double, std::milli>();
const std::lock_guard<std::mutex> lock(metrics_mutex);
auto client_num = this_job.client_metrics.size()+1;
//UX
sscout << client_num << math::numerical_suffix(client_num) << " client response\n"

View File

@ -37,12 +37,20 @@ namespace metrics
inline void to_json(json& j, const job& p)
{
auto total_trip_time = 0.;
auto summation_time = 0.f;
for(auto&& client : p.client_metrics)
{
summation_time += client.trip_time;
#ifdef THREADED
total_trip_time = client.trip_time > total_trip_time ? client.trip_time : total_trip_time;
#else
total_trip_time += client.trip_time;
j = json{
#endif
}
j = json{
{ "operation", p.operation },
{ "total_trip_time", total_trip_time },
{ "average_trip_time",total_trip_time / p.client_metrics.size() },
{ "average_trip_time",summation_time / p.client_metrics.size() },
{ "client_metrics", p.client_metrics}
};
}