Skip to content

Commit 00f87f3

Browse files
2 parents 2e7a0d4 + d1e339f commit 00f87f3

3 files changed

Lines changed: 43 additions & 6 deletions

File tree

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
set nocount on;
2+
go
3+
4+
drop table if exists #results;
5+
go
6+
7+
create table #results
8+
(
9+
[packages] nvarchar(100) not null,
10+
[installed] bit not null
11+
);
12+
go
13+
14+
drop procedure if exists #stpCheckInstalledPackages;
15+
go
16+
17+
create procedure #stpCheckInstalledPackages
18+
as
19+
exec sp_execute_external_script @language=N'R',
20+
@script=N'
21+
packages = c("plyr", "zoo")
22+
packagesInstalled = packages %in% rownames(installed.packages())
23+
OutputDataSet = data.frame(packages, packagesInstalled)
24+
'
25+
with result sets (as object #results)
26+
go
27+
28+
insert into #results exec #stpCheckInstalledPackages
29+
go
30+
31+
if (exists(select * from #results where installed = 0))
32+
throw 50000, 'Needed packages are not installed', 1;
33+
go

‎PredictiveMaintenance/SQLR/README.md‎

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,8 @@ To run the scripts, you must prepare the following environment:
4444
* An instance of SQL Server 2016 (Enterprise or Developer edition) CTP 3 or later, with SQL Server R Services installed and configured
4545
* A SQL login and password. The SQL login must have permissions to execute R scripts
4646
* A database on the instance in which the login has been granted the permission to create and execute stored procedures
47-
48-
* For more information about SQL Server 2016 and SQL Server R Services, please visit:
49-
https://msdn.microsoft.com/en-us/library/mt604847.aspx
47+
* The "plyr" and "zoo" R packages are needed. To install packages into the R Services environment please read here: https://msdn.microsoft.com/en-us/library/mt591989.aspx
48+
* For more information about SQL Server 2016 and SQL Server R Services, please visit: https://msdn.microsoft.com/en-us/library/mt604847.aspx
5049

5150
###WORKFLOW AUTOMATION
5251
-------------------
@@ -57,15 +56,15 @@ The following graph shows the overall work flow. The blue block represents each
5756

5857
The end-to-end workflow is fully automated by using a PowerShell script. To learn how to run the script, open a PowerShell command prompt, and type:
5958

60-
Get-Help SQLR-Predictive-Maintenance.ps1
59+
Get-Help .\SQLR-Predictive-Maintenance.ps1
6160

6261
To train and evaluate the models, you may run it as:
6362

64-
SQLR-Predictive-Maintenance.ps1 -server [SQL Server instance name] -dbname [database name]
63+
SQLR-Predictive-Maintenance.ps1 -ServerName [SQL Server instance name] -DBName [database name]
6564

6665
To score the production data, you may specify the -Score option:
6766

68-
SQLR-Predictive-Maintenance.ps1 -server [SQL Server instance name] -dbname [database name] -Score
67+
SQLR-Predictive-Maintenance.ps1 -ServerName [SQL Server instance name] -DBName [database name] -Score
6968

7069
The following chart shows the workflow. In the chart, the blue parallelogram represents the action to take. Before each step, the user will have the choice to continue, skip or exit.
7170

‎PredictiveMaintenance/SQLR/SQLR-Predictive-Maintenance.ps1‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,11 @@ if ($ans -eq 'y' -or $ans -eq 'Y')
182182
{
183183
try
184184
{
185+
# check if required R packages are installed
186+
Write-Host -ForeGroundColor 'green' ("Check required R packages")
187+
$script = $filePath + "DataProcessing\check_packages.sql"
188+
ExecuteSQL $script
189+
185190
# create training and test tables
186191
Write-Host -ForeGroundColor 'green' ("Create SQL tables: PM_train, PM_test, PM_truth and PM_models:")
187192
$script = $filePath + "DataProcessing\create_table.sql"

0 commit comments

Comments
 (0)