Update Finnish translation
[banshee.git] / extras / metrics / MultiUserSample.cs
blob1b015582feb58e67d7147b960f742f2a7b19483a
1 //
2 // MultiUserSample.cs
3 //
4 // Author:
5 // Gabriel Burt <gabriel.burt@gmail.com>
6 //
7 // Copyright (c) 2010 Novell, Inc.
8 //
9 // Permission is hereby granted, free of charge, to any person obtaining a copy
10 // of this software and associated documentation files (the "Software"), to deal
11 // in the Software without restriction, including without limitation the rights
12 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 // copies of the Software, and to permit persons to whom the Software is
14 // furnished to do so, subject to the following conditions:
16 // The above copyright notice and this permission notice shall be included in
17 // all copies or substantial portions of the Software.
19 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25 // THE SOFTWARE.
27 using System;
29 using Hyena;
30 using Hyena.Metrics;
31 using Hyena.Data.Sqlite;
32 using Hyena.Json;
34 namespace metrics
36 public class MultiUserSample : Sample, Hyena.Data.ICacheableItem
38 [DatabaseColumn (Index = "SampleUserIdIndex")]
39 public long UserId;
41 [DatabaseColumn (Index = "SampleMetricIdIndex")]
42 public long MetricId;
44 // ICacheableItem
45 public object CacheEntryId { get; set; }
46 public long CacheModelId { get; set; }
48 public MultiUserSample ()
52 static DateTime value_dt;
53 static TimeSpan value_span;
54 public static MultiUserSample Import (Database db, string user_id, string metric_name, string stamp, object val)
56 var sample = new MultiUserSample ();
57 sample.UserId = db.GetUser (user_id).Id;
59 // TODO collapse various DAP and DAAP library stats?
60 sample.MetricId = db.GetMetric (metric_name).Id;
62 DateTime stamp_dt;
63 if (!DateTimeUtil.TryParseInvariant (stamp, out stamp_dt)) {
64 Hyena.Log.Error ("Invalid stamp: ", stamp);
65 return null;
68 sample.Stamp = stamp_dt;
70 string value_str = val as string;
71 if (value_str != null) {
72 if (DateTimeUtil.TryParseInvariant (val as string, out value_dt)) {
73 // We want numeric dates to compare with
74 sample.Value = DateTimeUtil.ToTimeT (value_dt).ToString ();
75 } else if (value_str.Contains (":") && TimeSpan.TryParse (val as string, out value_span)) {
76 sample.Value = value_span.TotalMilliseconds.ToString ();
80 if (sample.Value == null) {
81 sample.SetValue (val);
84 return sample;