mirror of
https://github.com/Freika/dawarich.git
synced 2026-01-10 01:01:39 -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
|
||||
|
||||
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
|
||||
|
|
|
|||
|
|
@ -90,15 +90,16 @@ module Users
|
|||
end
|
||||
|
||||
def calculate_time_spent
|
||||
country_minutes = calculate_actual_country_minutes
|
||||
|
||||
{
|
||||
'countries' => calculate_country_time_spent,
|
||||
'cities' => calculate_city_time_spent
|
||||
'countries' => format_top_countries(country_minutes),
|
||||
'cities' => calculate_city_time_spent,
|
||||
'total_country_minutes' => country_minutes.values.sum
|
||||
}
|
||||
end
|
||||
|
||||
def calculate_country_time_spent
|
||||
country_minutes = calculate_actual_country_minutes
|
||||
|
||||
def format_top_countries(country_minutes)
|
||||
country_minutes
|
||||
.sort_by { |_, minutes| -minutes }
|
||||
.first(10)
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
import { test as setup, expect } from '@playwright/test';
|
||||
import { disableGlobeProjection } from '../v2/helpers/setup.js';
|
||||
|
||||
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)
|
||||
await page.waitForURL(/\/map(\/v[12])?/, { timeout: 10000 });
|
||||
|
||||
// Disable globe projection to ensure consistent E2E test behavior
|
||||
await disableGlobeProjection(page);
|
||||
|
||||
// Save authentication state
|
||||
await page.context().storageState({ path: authFile });
|
||||
});
|
||||
|
|
|
|||
|
|
@ -2,6 +2,33 @@
|
|||
* 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
|
||||
* @param {Page} page - Playwright page object
|
||||
|
|
|
|||
|
|
@ -31,7 +31,8 @@ RSpec.describe Users::SafeSettings do
|
|||
speed_color_scale: nil,
|
||||
fog_of_war_threshold: nil,
|
||||
enabled_map_layers: %w[Routes Heatmap],
|
||||
maps_maplibre_style: 'light'
|
||||
maps_maplibre_style: 'light',
|
||||
globe_projection: false
|
||||
}
|
||||
)
|
||||
end
|
||||
|
|
@ -82,7 +83,8 @@ RSpec.describe Users::SafeSettings do
|
|||
'visits_suggestions_enabled' => false,
|
||||
'enabled_map_layers' => %w[Points Routes Areas Photos],
|
||||
'maps_maplibre_style' => 'light',
|
||||
'digest_emails_enabled' => true
|
||||
'digest_emails_enabled' => true,
|
||||
'globe_projection' => false
|
||||
}
|
||||
)
|
||||
end
|
||||
|
|
@ -110,7 +112,8 @@ RSpec.describe Users::SafeSettings do
|
|||
speed_color_scale: nil,
|
||||
fog_of_war_threshold: nil,
|
||||
enabled_map_layers: %w[Points Routes Areas Photos],
|
||||
maps_maplibre_style: 'light'
|
||||
maps_maplibre_style: 'light',
|
||||
globe_projection: false
|
||||
}
|
||||
)
|
||||
end
|
||||
|
|
|
|||
Loading…
Reference in a new issue