mirror of
https://github.com/Freika/dawarich.git
synced 2026-01-11 09:41:40 -05:00
Update time spent calculation for country minutes in user digests
This commit is contained in:
parent
fc2707a609
commit
6f8bdce9f4
5 changed files with 47 additions and 9 deletions
|
|
@ -162,6 +162,9 @@ class Users::Digest < ApplicationRecord
|
||||||
end
|
end
|
||||||
|
|
||||||
def total_tracked_minutes
|
def total_tracked_minutes
|
||||||
top_countries_by_time.sum { |country| country['minutes'].to_i }
|
# Use total_country_minutes if available (new digests),
|
||||||
|
# fall back to summing top_countries_by_time (existing digests)
|
||||||
|
time_spent_by_location['total_country_minutes'] ||
|
||||||
|
top_countries_by_time.sum { |country| country['minutes'].to_i }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -90,15 +90,16 @@ module Users
|
||||||
end
|
end
|
||||||
|
|
||||||
def calculate_time_spent
|
def calculate_time_spent
|
||||||
|
country_minutes = calculate_actual_country_minutes
|
||||||
|
|
||||||
{
|
{
|
||||||
'countries' => calculate_country_time_spent,
|
'countries' => format_top_countries(country_minutes),
|
||||||
'cities' => calculate_city_time_spent
|
'cities' => calculate_city_time_spent,
|
||||||
|
'total_country_minutes' => country_minutes.values.sum
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
def calculate_country_time_spent
|
def format_top_countries(country_minutes)
|
||||||
country_minutes = calculate_actual_country_minutes
|
|
||||||
|
|
||||||
country_minutes
|
country_minutes
|
||||||
.sort_by { |_, minutes| -minutes }
|
.sort_by { |_, minutes| -minutes }
|
||||||
.first(10)
|
.first(10)
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
import { test as setup, expect } from '@playwright/test';
|
import { test as setup, expect } from '@playwright/test';
|
||||||
|
import { disableGlobeProjection } from '../v2/helpers/setup.js';
|
||||||
|
|
||||||
const authFile = 'e2e/temp/.auth/user.json';
|
const authFile = 'e2e/temp/.auth/user.json';
|
||||||
|
|
||||||
|
|
@ -19,6 +20,9 @@ setup('authenticate', async ({ page }) => {
|
||||||
// Wait for successful navigation to map (v1 or v2 depending on user preference)
|
// Wait for successful navigation to map (v1 or v2 depending on user preference)
|
||||||
await page.waitForURL(/\/map(\/v[12])?/, { timeout: 10000 });
|
await page.waitForURL(/\/map(\/v[12])?/, { timeout: 10000 });
|
||||||
|
|
||||||
|
// Disable globe projection to ensure consistent E2E test behavior
|
||||||
|
await disableGlobeProjection(page);
|
||||||
|
|
||||||
// Save authentication state
|
// Save authentication state
|
||||||
await page.context().storageState({ path: authFile });
|
await page.context().storageState({ path: authFile });
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,33 @@
|
||||||
* Helper functions for Maps V2 E2E tests
|
* Helper functions for Maps V2 E2E tests
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Disable globe projection setting via API
|
||||||
|
* This ensures consistent map rendering for E2E tests
|
||||||
|
* @param {Page} page - Playwright page object
|
||||||
|
*/
|
||||||
|
export async function disableGlobeProjection(page) {
|
||||||
|
// Get API key from the page (requires being logged in)
|
||||||
|
const apiKey = await page.evaluate(() => {
|
||||||
|
const metaTag = document.querySelector('meta[name="api-key"]');
|
||||||
|
return metaTag?.content;
|
||||||
|
});
|
||||||
|
|
||||||
|
if (apiKey) {
|
||||||
|
await page.request.patch('/api/v1/settings', {
|
||||||
|
headers: {
|
||||||
|
'Authorization': `Bearer ${apiKey}`,
|
||||||
|
'Content-Type': 'application/json'
|
||||||
|
},
|
||||||
|
data: {
|
||||||
|
settings: {
|
||||||
|
globe_projection: false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Navigate to Maps V2 page
|
* Navigate to Maps V2 page
|
||||||
* @param {Page} page - Playwright page object
|
* @param {Page} page - Playwright page object
|
||||||
|
|
|
||||||
|
|
@ -31,7 +31,8 @@ RSpec.describe Users::SafeSettings do
|
||||||
speed_color_scale: nil,
|
speed_color_scale: nil,
|
||||||
fog_of_war_threshold: nil,
|
fog_of_war_threshold: nil,
|
||||||
enabled_map_layers: %w[Routes Heatmap],
|
enabled_map_layers: %w[Routes Heatmap],
|
||||||
maps_maplibre_style: 'light'
|
maps_maplibre_style: 'light',
|
||||||
|
globe_projection: false
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
@ -82,7 +83,8 @@ RSpec.describe Users::SafeSettings do
|
||||||
'visits_suggestions_enabled' => false,
|
'visits_suggestions_enabled' => false,
|
||||||
'enabled_map_layers' => %w[Points Routes Areas Photos],
|
'enabled_map_layers' => %w[Points Routes Areas Photos],
|
||||||
'maps_maplibre_style' => 'light',
|
'maps_maplibre_style' => 'light',
|
||||||
'digest_emails_enabled' => true
|
'digest_emails_enabled' => true,
|
||||||
|
'globe_projection' => false
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
@ -110,7 +112,8 @@ RSpec.describe Users::SafeSettings do
|
||||||
speed_color_scale: nil,
|
speed_color_scale: nil,
|
||||||
fog_of_war_threshold: nil,
|
fog_of_war_threshold: nil,
|
||||||
enabled_map_layers: %w[Points Routes Areas Photos],
|
enabled_map_layers: %w[Points Routes Areas Photos],
|
||||||
maps_maplibre_style: 'light'
|
maps_maplibre_style: 'light',
|
||||||
|
globe_projection: false
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue