Skip to content

Commit

Permalink
Statistics in the DB
Browse files Browse the repository at this point in the history
  • Loading branch information
Andy Kramolisch committed Apr 17, 2012
1 parent 27d453c commit 066dff9
Show file tree
Hide file tree
Showing 12 changed files with 627 additions and 22 deletions.
1 change: 1 addition & 0 deletions ActivEarth.Objects/ActivEarth.Objects.csproj
Expand Up @@ -71,6 +71,7 @@
<Compile Include="Profile\ProfileVisibility.cs" />
<Compile Include="Profile\Statistic.cs" />
<Compile Include="Profile\User.cs" />
<Compile Include="Profile\UserStatistic.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
Expand Down
38 changes: 27 additions & 11 deletions ActivEarth.Objects/Profile/User.cs
Expand Up @@ -134,7 +134,7 @@ public PrivacySetting userPrivacySettings
set;
}

private Dictionary<Statistic, float> _stats;
private Dictionary<Statistic, UserStatistic> _stats;

#endregion ---------- Private Members ----------

Expand All @@ -153,14 +153,7 @@ public User(string firstname, string lastname)

this.ChallengeInitialValues = new Dictionary<int, float>();

_stats = new Dictionary<Statistic, float>();

_stats.Add(Statistic.BikeDistance, 0);
_stats.Add(Statistic.ChallengesCompleted, 0);
_stats.Add(Statistic.GasSavings, 0);
_stats.Add(Statistic.RunDistance, 0);
_stats.Add(Statistic.Steps, 0);
_stats.Add(Statistic.WalkDistance, 0);
_stats = new Dictionary<Statistic, UserStatistic>();

this.Badges = new Dictionary<Statistic, Badge>();
this.Contests = new List<Contest>();
Expand All @@ -175,12 +168,35 @@ public User(string firstname, string lastname)

public float GetStatistic(Statistic statToGet)
{
return _stats[statToGet];
if (_stats.ContainsKey(statToGet))
{
return _stats[statToGet].value;
}
else
{
return 0;
}
}

public void SetStatistic(Statistic statToSet, float val)
{
_stats[statToSet] = val;
if (_stats.ContainsKey(statToSet))
{
_stats[statToSet].value = val;
}
else
{
_stats[statToSet] = new UserStatistic(statToSet, val);
}
}

/// <summary>
/// Sets in memory statistic values.
/// </summary>
/// <param name="stats">Dictionary mapping statistics to values.</param>
public void SetStatisticsDict(Dictionary<Statistic, UserStatistic> stats)
{
_stats = stats;
}

#endregion ---------- Public Methods ----------
Expand Down
55 changes: 55 additions & 0 deletions ActivEarth.Objects/Profile/UserStatistic.cs
@@ -0,0 +1,55 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace ActivEarth.Objects.Profile
{
public class UserStatistic
{
#region ---------- Public Members ----------

public int UserStatisticID
{
get;
set;
}

public int UserID
{
get;
set;
}

public Statistic statistic
{
get;
set;
}

public float value
{
get;
set;
}

#endregion ---------- Public Members ----------

#region ---------- Constructor ----------

public UserStatistic(Statistic stat)
: this(stat, 0)
{

}

public UserStatistic(Statistic stat, float val)
{
statistic = stat;
value = val;
}

#endregion ---------- Constructor ----------

}
}
4 changes: 3 additions & 1 deletion ActivEarth.Server.Service/ActivEarth.Server.Data.csproj
Expand Up @@ -57,12 +57,14 @@
<DesignTime>True</DesignTime>
<DependentUpon>ActivEarthDataProviders.dbml</DependentUpon>
</Compile>
<Compile Include="ChallengeManager.cs" />
<Compile Include="StatisticManager.cs" />
<Compile Include="ConnectionManager.cs" />
<Compile Include="ContestManager.cs" />
<Compile Include="ChallengeManager.cs" />
<Compile Include="DAO\ChallengeDAO.cs" />
<Compile Include="DAO\ContestDAO.cs" />
<Compile Include="DAO\PrivacySettingDAO.cs" />
<Compile Include="DAO\UserStatisticDAO.cs" />
<Compile Include="DAO\TeamDAO.cs" />
<Compile Include="DAO\UserDAO.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
Expand Down
14 changes: 12 additions & 2 deletions ActivEarth.Server.Service/ActivEarthDataProviders.dbml
Expand Up @@ -23,7 +23,8 @@
<Column Name="user_name" Type="System.String" DbType="VarChar(100) NOT NULL" CanBeNull="false" />
<Column Name="password" Type="System.String" DbType="VarChar(20) NOT NULL" CanBeNull="false" />
<Association Name="UserDataProvider_ProfileDataProvider" Member="ProfileDataProviders" ThisKey="id" OtherKey="user_id" Type="ProfileDataProvider" />
<Association Name="UserDataProvider_privacy_setting" Member="PrivacySettingDataProviders" Storage="_privacy_settings" ThisKey="id" OtherKey="user_id" Type="PrivacySettingDataProvider" />
<Association Name="UserDataProvider_PrivacySettingDataProvider" Member="PrivacySettingDataProviders" Storage="_privacy_settings" ThisKey="id" OtherKey="user_id" Type="PrivacySettingDataProvider" />
<Association Name="UserDataProvider_StatisticDataProvider" Member="UserStatisticDataProviders" Storage="_StatisticDataProviders" ThisKey="id" OtherKey="user_id" Type="UserStatisticDataProvider" />
</Type>
</Table>
<Table Name="dbo.challenges" Member="ChallengeDataProviders">
Expand Down Expand Up @@ -87,7 +88,16 @@
<Column Name="weight" Type="System.Boolean" DbType="Bit NOT NULL" CanBeNull="false" />
<Column Name="height" Type="System.Boolean" DbType="Bit NOT NULL" CanBeNull="false" />
<Column Name="groups" Type="System.Boolean" DbType="Bit NOT NULL" CanBeNull="false" />
<Association Name="UserDataProvider_privacy_setting" Member="UserDataProvider" ThisKey="user_id" OtherKey="id" Type="UserDataProvider" IsForeignKey="true" />
<Association Name="UserDataProvider_PrivacySettingDataProvider" Member="UserDataProvider" ThisKey="user_id" OtherKey="id" Type="UserDataProvider" IsForeignKey="true" />
</Type>
</Table>
<Table Name="dbo.[statistics]" Member="UserStatisticDataProviders">
<Type Name="UserStatisticDataProvider">
<Column Name="id" Type="System.Int32" DbType="Int NOT NULL" IsPrimaryKey="true" CanBeNull="false" />
<Column Name="user_id" Type="System.Int32" DbType="Int NOT NULL" CanBeNull="false" />
<Column Name="statistic_type" Type="System.Byte" DbType="TinyInt NOT NULL" CanBeNull="false" />
<Column Name="value" Type="System.Double" DbType="Float NOT NULL" CanBeNull="false" />
<Association Name="UserDataProvider_StatisticDataProvider" Member="UserDataProvider" ThisKey="user_id" OtherKey="id" Type="UserDataProvider" IsForeignKey="true" />
</Type>
</Table>
</Database>
23 changes: 18 additions & 5 deletions ActivEarth.Server.Service/ActivEarthDataProviders.dbml.layout
Expand Up @@ -2,10 +2,10 @@
<ordesignerObjectsDiagram dslVersion="1.0.0.0" absoluteBounds="0, 0, 11, 9.5" name="ActivEarthDataProviders">
<DataContextMoniker Name="/ActivEarthDataProvidersDataContext" />
<nestedChildShapes>
<classShape Id="9bb1702d-ae42-4e39-b110-5325cd3e0737" absoluteBounds="3.375, 1.75, 2, 2.9247054036458326">
<classShape Id="9bb1702d-ae42-4e39-b110-5325cd3e0737" absoluteBounds="3.375, 2, 2, 2.9247054036458326">
<DataClassMoniker Name="/ActivEarthDataProvidersDataContext/ProfileDataProvider" />
<nestedChildShapes>
<elementListCompartment Id="6782f308-3001-417d-ada8-fb14091ed645" absoluteBounds="3.39, 2.21, 1.9700000000000002, 2.364705403645833" name="DataPropertiesCompartment" titleTextColor="Black" itemTextColor="Black" />
<elementListCompartment Id="6782f308-3001-417d-ada8-fb14091ed645" absoluteBounds="3.39, 2.46, 1.9700000000000002, 2.364705403645833" name="DataPropertiesCompartment" titleTextColor="Black" itemTextColor="Black" />
</nestedChildShapes>
</classShape>
<classShape Id="3e8324b9-399b-4069-bdc7-7aded2dfc2e7" absoluteBounds="0.5, 1.75, 2, 1.3862939453125">
Expand All @@ -14,7 +14,7 @@
<elementListCompartment Id="78e6d7af-4e77-4492-8b53-07ca5cd3b534" absoluteBounds="0.515, 2.21, 1.9700000000000002, 0.8262939453125" name="DataPropertiesCompartment" titleTextColor="Black" itemTextColor="Black" />
</nestedChildShapes>
</classShape>
<associationConnector edgePoints="[(2.5 : 2.44314697265625); (3.375 : 2.44314697265625)]" fixedFrom="NotFixed" fixedTo="NotFixed">
<associationConnector edgePoints="[(2.5 : 2.56814697265625); (3.375 : 2.56814697265625)]" fixedFrom="NotFixed" fixedTo="NotFixed">
<AssociationMoniker Name="/ActivEarthDataProvidersDataContext/UserDataProvider/UserDataProvider_ProfileDataProvider" />
<nodes>
<classShapeMoniker Id="3e8324b9-399b-4069-bdc7-7aded2dfc2e7" />
Expand Down Expand Up @@ -45,7 +45,7 @@
<elementListCompartment Id="7c1f08c9-e80b-4c08-82a4-71848fe12e08" absoluteBounds="3.3900000000000006, 5.96, 1.9700000000000002, 1.0185953776041665" name="DataPropertiesCompartment" titleTextColor="Black" itemTextColor="Black" />
</nestedChildShapes>
</classShape>
<associationConnector edgePoints="[(5.375 : 3.89985270182292); (6.625 : 3.89985270182292)]" fixedFrom="NotFixed" fixedTo="NotFixed">
<associationConnector edgePoints="[(5.375 : 4.01044840494792); (6.625 : 4.01044840494792)]" fixedFrom="NotFixed" fixedTo="NotFixed">
<AssociationMoniker Name="/ActivEarthDataProvidersDataContext/ProfileDataProvider/ProfileDataProvider_TeamMemberDataProvider" />
<nodes>
<classShapeMoniker Id="9bb1702d-ae42-4e39-b110-5325cd3e0737" />
Expand Down Expand Up @@ -73,11 +73,24 @@
</nestedChildShapes>
</classShape>
<associationConnector edgePoints="[(1.5 : 3.1362939453125); (1.5 : 3.5)]" fixedFrom="NotFixed" fixedTo="NotFixed">
<AssociationMoniker Name="/ActivEarthDataProvidersDataContext/UserDataProvider/UserDataProvider_privacy_setting" />
<AssociationMoniker Name="/ActivEarthDataProvidersDataContext/UserDataProvider/UserDataProvider_PrivacySettingDataProvider" />
<nodes>
<classShapeMoniker Id="3e8324b9-399b-4069-bdc7-7aded2dfc2e7" />
<classShapeMoniker Id="71aae01b-9aed-4edd-8b53-63a55696a73f" />
</nodes>
</associationConnector>
<classShape Id="bc337936-6b01-4170-aa51-6ff584cc2d50" absoluteBounds="6.625, 1.25, 2, 1.5785953776041666">
<DataClassMoniker Name="/ActivEarthDataProvidersDataContext/UserStatisticDataProvider" />
<nestedChildShapes>
<elementListCompartment Id="54580559-3687-4c7b-9158-69aba09bfc05" absoluteBounds="6.64, 1.71, 1.9700000000000002, 1.0185953776041665" name="DataPropertiesCompartment" titleTextColor="Black" itemTextColor="Black" />
</nestedChildShapes>
</classShape>
<associationConnector edgePoints="[(2.5 : 1.84375); (6.625 : 1.84375)]" fixedFrom="Algorithm" fixedTo="Algorithm">
<AssociationMoniker Name="/ActivEarthDataProvidersDataContext/UserDataProvider/UserDataProvider_StatisticDataProvider" />
<nodes>
<classShapeMoniker Id="3e8324b9-399b-4069-bdc7-7aded2dfc2e7" />
<classShapeMoniker Id="bc337936-6b01-4170-aa51-6ff584cc2d50" />
</nodes>
</associationConnector>
</nestedChildShapes>
</ordesignerObjectsDiagram>

0 comments on commit 066dff9

Please sign in to comment.