The total duration of each activity is calculated starting from 0:00 of
the current day. Last activity is calculated until current time (today)
or 00:00 of the next day.
This commit is contained in:
Lucian Tomuta 2014-10-07 12:46:59 +03:00
Родитель 844212d103
Коммит 65d3ae172d
5 изменённых файлов: 77 добавлений и 22 удалений

Просмотреть файл

@ -12,7 +12,10 @@ namespace ActivitiesExample.Converters
{
public object Convert(object value, Type targetType, object parameter, string language)
{
return (352 * ((TimeSpan)value).TotalMinutes) / (12*60);
// 320 is an ugly hardcoded value for list width (350) - elipsis column (30)
// would be nice if could be suplied as 'parameter' via a binding to list's ActualWidth
// but ConverterParameter is non-bindable :(
return (320 * ((TimeSpan)value).TotalMinutes) / (12*60);
}
public object ConvertBack(object value, Type targetType, object parameter, string language)

Просмотреть файл

@ -7,6 +7,7 @@ using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;
using Windows.UI.Popups;
using Windows.UI.Xaml;
@ -140,22 +141,69 @@ namespace ActivitiesExample.Data
indexer.Add(values[i], i);
}
// skip fist returned entry, it is outside of our requested time interval
for (int i = 1; i < _history.Count - 1; i++)
// there could be days with no data (e.g. of phone was turned off)
if(_history.Count>0)
{
ActivityMonitorReading current = _history[i];
ActivityMonitorReading next = _history[i + 1];
// first entry may be from previous time window, is there any data from current time window?
bool hasDataInTimeWindow = false;
// insert new fist entry, representing the last activity of the previous time window
// this helps capture that activity's duration but only from the start of current time window
ActivityMonitorReading first = _history[0];
if(first.Timestamp <= DateTime.Now.Date.AddDays(timeWindowIndex))
{
// create new "first" entry, with the same mode but timestamp set as 0:00h in current time window
_history.Insert(1, new ActivityMonitorReading(first.Mode, DateTime.Now.Date.AddDays(timeWindowIndex)));
// remove previous entry
_history.RemoveAt(0);
hasDataInTimeWindow = _history.Count > 1;
}
else
{
// the first entry belongs to the current time window
// there is no known activity before it
hasDataInTimeWindow = true;
}
_durations[indexer[current.Mode]] += next.Timestamp - current.Timestamp;
// if at least one activity is recorded in this time window
if(hasDataInTimeWindow)
{
// insert a last activity, marking the begining of the next time window
// this helps capturing the correct duration of the last activity stated in this time window
ActivityMonitorReading last = _history.Last();
if (last.Timestamp < DateTime.Now.Date.AddDays(timeWindowIndex + 1))
{
// is this today's time window
if (timeWindowIndex == 0)
{
// last activity duration measured until this instant time
_history.Add(new ActivityMonitorReading(last.Mode, DateTime.Now));
}
else
{
// last activity measured until the begining of the next time index
_history.Add(new ActivityMonitorReading(last.Mode, DateTime.Now.Date.AddDays(timeWindowIndex + 1)));
}
}
// calculate duration for each current activity by subtracting its timestamp from that of the next one
for (int i = 0; i < _history.Count - 1; i++)
{
ActivityMonitorReading current = _history[i];
ActivityMonitorReading next = _history[i + 1];
_durations[indexer[current.Mode]] += next.Timestamp - current.Timestamp;
}
}
}
// populate the list to be displayed in the UI
for (int i = 0; i < _activitiesList.Count; i++)
{
_ListData.Add(new MyQuantifiedData(_activitiesList[i], _durations[i]));
}
}
Debug.WriteLine("ListData changed");
NotifyPropertyChanged("ListData");
}

Просмотреть файл

@ -48,32 +48,36 @@
</StackPanel>
<!-- current activity icon -->
<Image Source="{Binding CurrentActivity, Converter={StaticResource ActivityToIcon}}" Grid.Row="2" Opacity=".1" Height="300" Width="300"/>
<Image Source="{Binding CurrentActivity, Converter={StaticResource ActivityToIcon}}" Grid.Row="2" Height="300" Width="300" Opacity="0.3"/>
<!-- List of activities -->
<TextBlock Text="{Binding Path=TimeWindow, Converter={StaticResource ResourceKey=TimeWindowToString}, Mode=OneWay}" Grid.Row="1" Margin="24,0,0,6" FontSize="{StaticResource TextStyleMediumFontSize}"/>
<ListView x:Name="ActivityListView" Grid.Row="2" Margin="24,0" ItemsSource="{Binding Path=ListData, Mode=OneWay}" Background="#3FFFFFFF" SelectionMode="None" Height="310">
<ListView.ItemTemplate>
<DataTemplate>
<Grid Margin="0" Height="60">
<Grid Margin="0" Height="60" Width="{Binding ActualWidth, ElementName=ActivityListView, Mode=OneWay}">
<Grid.RowDefinitions >
<RowDefinition Height="auto"/>
<RowDefinition Height="10"/>
<RowDefinition Height="auto"/>
<RowDefinition Height="auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="95*"/>
<ColumnDefinition Width="227*"/>
<ColumnDefinition Width="*"/>
<!-- 30px reserved for elipsis -->
<ColumnDefinition Width="30"/>
</Grid.ColumnDefinitions>
<StackPanel Grid.ColumnSpan="3" Orientation="Horizontal" Margin="12,8,-0.333,0" Grid.RowSpan="2" >
<!-- Activity name and durations -->
<StackPanel Orientation="Horizontal" Grid.Row="1" Margin="12,0,0,0" >
<TextBlock Text="{Binding Path=ActivityName}" FontSize="{StaticResource TextStyleMediumFontSize}" Foreground="White" VerticalAlignment="Center"/>
<TextBlock Text="{Binding Path=ActivityTime, Converter={StaticResource ResourceKey=TimeToString}}" FontSize="{StaticResource TextStyleMediumFontSize}" Foreground="White" Margin="12,0,0,0" VerticalAlignment="Center"/>
</StackPanel>
<TextBlock Grid.Row="2" Text="{Binding Path=ActivityName, Converter={StaticResource ResourceKey=ActivityToHint}}" FontSize="{StaticResource TextStyleSmallFontSize}" Foreground="White" VerticalAlignment="Center" Margin="12,0,29.667,5.833" Grid.ColumnSpan="3"/>
<Rectangle Margin="0,0.167,-29.333,0" Grid.Row="3" Grid.Column="0" Width="{Binding Path=ActivityTime, Converter={StaticResource ResourceKey=TimeToWidth}}" Height="6" Fill="White" VerticalAlignment="Top" HorizontalAlignment="Left" Grid.ColumnSpan="3"/>
<StackPanel Grid.Row="3" Grid.Column="2" Orientation="Horizontal" Visibility="{Binding ActivityTime, Converter={StaticResource VisibleElipsis}}" Margin="0.333,0.167,-0.333,0">
<!-- Activity description -->
<TextBlock Grid.Row="2" Text="{Binding Path=ActivityName, Converter={StaticResource ResourceKey=ActivityToHint}}" FontSize="{StaticResource TextStyleSmallFontSize}" Foreground="White" VerticalAlignment="Center" Margin="12,1,12.667,5.833" Height="14"/>
<!-- Activity duration as a rectangle -->
<Rectangle Grid.Row="3" Grid.Column="0" Width="{Binding Path=ActivityTime, Converter={StaticResource ResourceKey=TimeToWidth}}" Height="6" Fill="White" VerticalAlignment="Top" HorizontalAlignment="Left"/>
<!-- Elipsis added to the end of rectangle if duration > 12h -->
<StackPanel Grid.Row="3" Grid.Column="1" Orientation="Horizontal" Visibility="{Binding ActivityTime, Converter={StaticResource VisibleElipsis}}">
<Rectangle Margin="6,0,0,0" Width="6" Height="6" Fill="White" HorizontalAlignment="Left" VerticalAlignment="Top"/>
<Rectangle Margin="6,0,0,0" Width="6" Height="6" Fill="White" HorizontalAlignment="Right" VerticalAlignment="Top"/>
</StackPanel>

Просмотреть файл

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<Package xmlns="http://schemas.microsoft.com/appx/2010/manifest" xmlns:m2="http://schemas.microsoft.com/appx/2013/manifest" xmlns:m3="http://schemas.microsoft.com/appx/2014/manifest" xmlns:mp="http://schemas.microsoft.com/appx/2014/phone/manifest">
<Identity Name="74dcbd9a-3772-41a5-b7d4-f1e511e6b0cd" Publisher="CN=sujesh" Version="1.0.0.1" />
<Identity Name="74dcbd9a-3772-41a5-b7d4-f1e511e6b0cd" Publisher="CN=sujesh" Version="1.0.0.5" />
<Properties>
<DisplayName>Activities</DisplayName>
<PublisherDisplayName>Nokia Developer</PublisherDisplayName>

Просмотреть файл

@ -149,7 +149,7 @@
<value>activities</value>
</data>
<data name="ApplicationSuite.Text" xml:space="preserve">
<value>SENSORCORE SAMPLE</value>
<value>LUMIA SENSORCORE SAMPLE</value>
</data>
<data name="CurrentActivityHeader.Text" xml:space="preserve">
<value>Current activity:</value>
@ -172,16 +172,16 @@ The application will now exit.</value>
<value>Lumia SensorCore</value>
</data>
<data name="Hint.Idle" xml:space="preserve">
<value>The phone was laying still.</value>
<value>The phone was laying still, for example, on a table.</value>
</data>
<data name="Hint.Moving" xml:space="preserve">
<value>Some movement was detected, other than walkign or running.</value>
<value>Some movement was detected, other than walking or running.</value>
</data>
<data name="Hint.Running" xml:space="preserve">
<value>The user was running with the phone.</value>
</data>
<data name="Hint.Stationary" xml:space="preserve">
<value>The phone was handled but the user was not moving.</value>
<value>The phone was handled but the user was not moving around.</value>
</data>
<data name="Hint.Walking" xml:space="preserve">
<value>The user was walking with the phone.</value>
@ -196,7 +196,7 @@ The application will now exit.</value>
<value>refresh todays' activities</value>
</data>
<data name="RefreshButton.Label" xml:space="preserve">
<value>update history</value>
<value>update diagram</value>
</data>
<data name="TimeWindow.Today" xml:space="preserve">
<value>Today</value>