Skip to content

Commit

Permalink
Added another sample
Browse files Browse the repository at this point in the history
  • Loading branch information
Saveen Reddy committed Feb 21, 2017
1 parent 7acdc12 commit af5e4a3
Show file tree
Hide file tree
Showing 4 changed files with 133 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 14
VisualStudioVersion = 14.0.25420.1
MinimumVisualStudioVersion = 10.0.40219.1
Project("{182E2583-ECAD-465B-BB50-91101D7C24CE}") = "MVA_MaxParallelActivitiesReducer", "MVA_MaxParallelActivitiesReducer\MVA_MaxParallelActivitiesReducer.usqlproj", "{4409CA52-A006-4E68-947C-38717E45B584}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Debug|x64 = Debug|x64
Debug|x86 = Debug|x86
Release|Any CPU = Release|Any CPU
Release|x64 = Release|x64
Release|x86 = Release|x86
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{4409CA52-A006-4E68-947C-38717E45B584}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{4409CA52-A006-4E68-947C-38717E45B584}.Debug|Any CPU.Build.0 = Debug|Any CPU
{4409CA52-A006-4E68-947C-38717E45B584}.Debug|x64.ActiveCfg = Debug|x64
{4409CA52-A006-4E68-947C-38717E45B584}.Debug|x64.Build.0 = Debug|x64
{4409CA52-A006-4E68-947C-38717E45B584}.Debug|x86.ActiveCfg = Debug|x86
{4409CA52-A006-4E68-947C-38717E45B584}.Debug|x86.Build.0 = Debug|x86
{4409CA52-A006-4E68-947C-38717E45B584}.Release|Any CPU.ActiveCfg = Release|Any CPU
{4409CA52-A006-4E68-947C-38717E45B584}.Release|Any CPU.Build.0 = Release|Any CPU
{4409CA52-A006-4E68-947C-38717E45B584}.Release|x64.ActiveCfg = Release|x64
{4409CA52-A006-4E68-947C-38717E45B584}.Release|x64.Build.0 = Release|x64
{4409CA52-A006-4E68-947C-38717E45B584}.Release|x86.ActiveCfg = Release|x86
{4409CA52-A006-4E68-947C-38717E45B584}.Release|x86.Build.0 = Release|x86
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>4409ca52-a006-4e68-947c-38717e45b584</ProjectGuid>
<OutputType>File</OutputType>
<AssemblyName>Algebra.xml</AssemblyName>
<TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
<Name>MVA_MaxParallelActivitiesReducer</Name>
<RootNamespace>MVA_MaxParallelActivitiesReducer</RootNamespace>
<RuntimeVersion>default</RuntimeVersion>
<OutputStreamPath>C:\Users\saveenr\AppData\Local\USQLDataRoot</OutputStreamPath>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<OutputPath>bin\Debug\</OutputPath>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugSymbols>false</DebugSymbols>
<OutputPath>bin\Release\</OutputPath>
</PropertyGroup>
<ItemGroup>
<Script Include="Script.usql" />
<ScriptCode Include="Script.usql.cs">
<DependentUpon>Script.usql</DependentUpon>
</ScriptCode>
</ItemGroup>
<Import Project="$(AppData)\Microsoft\DataLake\MsBuild\1.0\Usql.targets" />
</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
@events =
SELECT * FROM
(VALUES
("c1",DateTime.Parse("2016-03-31T01:00:03.000Z"),"1","start"),
("c1",DateTime.Parse("2016-03-31T01:00:47.000Z"),"1","stop"),
("c1",DateTime.Parse("2016-03-31T01:00:28.000Z"),"2","start"),
("c1",DateTime.Parse("2016-03-31T01:00:51.000Z"),"2","stop"),
("c1",DateTime.Parse("2016-03-31T01:00:31.000Z"),"2","start"),
("c1",DateTime.Parse("2016-03-31T01:00:42.000Z"),"2","stop")
) AS
D( cohort, timestamp, id, op );

@results =
REDUCE @events
PRESORT timestamp ON cohort
PRODUCE cohort string, max int
USING new MVA_MaxParallelActivitiesReducer.RangeReducer();

OUTPUT @results
TO "/output.csv"
USING Outputters.Csv();
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
using Microsoft.Analytics.Interfaces;
using Microsoft.Analytics.Types.Sql;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;

namespace MVA_MaxParallelActivitiesReducer
{
public class RangeReducer : IReducer
{
public override IEnumerable<IRow> Reduce(IRowset input, IUpdatableRow output)
{
int acc = 0;
int max = 0;

foreach (var row in input.Rows)
{

var timestamp = row.Get<DateTime>("timestamp");
var op = row.Get<string>("op");
if (op == "start")
{
acc++;
}
else
{
acc--;
if (acc < 0)
{
acc = 0;
}
}

max = System.Math.Max(max, acc);

}

output.Set<string>("cohort", "FOO");
output.Set<int>("max", max);

yield return output.AsReadOnly();

}
}
}

0 comments on commit af5e4a3

Please sign in to comment.