* First Commit

* commit test

* git is case sensitive , that is really dumb

* testing data population

* added more csv files

* Loan_Data1000 added

* more files

* deleting data files

* added 10k csv files

* added 100k csv files

* 1million csv

* more 1 million csv files

* even more 1 million records csv files

* added unzip archive

* data file unzip

* added files to pull

* playing with csv files

* comment out unzipping routine

* file stuff

* removed old db name

* fixed path

* update file places

* checking in

* trying bcp

* turned off sample web as it is not needed

* updated to use txt files

* added force to bcp

* removed the force

* come to the dark side , we have cookies

* got rid of header in txt file

* got rid of pipe delimeter

* updated txt files

* removed header row from txt files

* futzing with bcp

* trying bulk insert

* figuring out bulk insert

* hardcoded bulk inserts

* added proper tick marks

* added comments

* added support for 100K records

* updated sql objects for 100k records

* Fixed a ton of stuff

* got rid of jupyter notebook password

* took out 100k imports

* fixed sproc name

* Updated Setup Path

* added standalone

* set standalone to no for testing

* if then else for Standalone

* yep

* yes

* nk

* trying to get isStandalone working

* trying to get standalone working

* final push
This commit is contained in:
v-robwhi 2018-02-02 12:27:33 -08:00 коммит произвёл GitHub
Родитель d70e275b16
Коммит df2b1ef964
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
20 изменённых файлов: 204579 добавлений и 484 удалений

10000
Data/loan_info_10k.txt Normal file

Разница между файлами не показана из-за своего большого размера Загрузить разницу

10000
Data/member_info_10k.txt Normal file

Разница между файлами не показана из-за своего большого размера Загрузить разницу

183765
Data/payments_info_10k.txt Normal file

Разница между файлами не показана из-за своего большого размера Загрузить разницу

Двоичные данные
LoanChargeOff.pbix Normal file

Двоичный файл не отображается.

13
R/LoanChargeOff.Rproj Normal file
Просмотреть файл

@ -0,0 +1,13 @@
Version: 1.0
RestoreWorkspace: Default
SaveWorkspace: Default
AlwaysSaveHistory: Default
EnableCodeIndexing: Yes
UseSpacesForTab: Yes
NumSpacesForTab: 2
Encoding: UTF-8
RnwWeave: Sweave
LaTeX: pdfLaTeX

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

@ -24,7 +24,7 @@
},
{
"cell_type": "code",
"execution_count": 1,
"execution_count": null,
"metadata": {
"collapsed": true
},
@ -37,14 +37,14 @@
},
{
"cell_type": "code",
"execution_count": 2,
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"# Replace username and password in the connection string with appropriate values.\n",
"sql_connection_string <- \"Driver=SQL Server;Server=.;Database=LoanChargeOff;UID=<sql username>;PWD=<sql password>\""
"sql_connection_string <- \"Driver=SQL Server;Server=.;Database=LoanChargeOff_R;Trusted_Connection=True\""
]
},
{
@ -57,7 +57,7 @@
},
{
"cell_type": "code",
"execution_count": 3,
"execution_count": null,
"metadata": {
"collapsed": true
},
@ -109,106 +109,11 @@
},
{
"cell_type": "code",
"execution_count": 4,
"execution_count": null,
"metadata": {
"collapsed": false
"collapsed": true
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Elapsed time: 00:00:00.6347310\n"
]
},
{
"data": {
"text/html": [
"<ol class=list-inline>\n",
"\t<li>'installment'</li>\n",
"\t<li>'loanAmount'</li>\n",
"\t<li>'past_due_5'</li>\n",
"\t<li>'term'</li>\n",
"\t<li>'past_due_4'</li>\n",
"\t<li>'past_due_3'</li>\n",
"\t<li>'past_due_2'</li>\n",
"\t<li>'past_due_1'</li>\n",
"\t<li>'past_due'</li>\n",
"\t<li>'branch.\"Bridgeport\"'</li>\n",
"\t<li>'numTotalCreditLines'</li>\n",
"\t<li>'branch.\"San Antonio\"'</li>\n",
"\t<li>'annualIncome'</li>\n",
"\t<li>'residentialState.\"NV\"'</li>\n",
"\t<li>'branch.\"Shreveport\"'</li>\n",
"\t<li>'residentialState.\"WV\"'</li>\n",
"\t<li>'branch.\"Spokane\"'</li>\n",
"\t<li>'branch.\"Gulfport\"'</li>\n",
"\t<li>'residentialState.\"VT\"'</li>\n",
"</ol>\n"
],
"text/latex": [
"\\begin{enumerate*}\n",
"\\item 'installment'\n",
"\\item 'loanAmount'\n",
"\\item 'past\\_due\\_5'\n",
"\\item 'term'\n",
"\\item 'past\\_due\\_4'\n",
"\\item 'past\\_due\\_3'\n",
"\\item 'past\\_due\\_2'\n",
"\\item 'past\\_due\\_1'\n",
"\\item 'past\\_due'\n",
"\\item 'branch.\"Bridgeport\"'\n",
"\\item 'numTotalCreditLines'\n",
"\\item 'branch.\"San Antonio\"'\n",
"\\item 'annualIncome'\n",
"\\item 'residentialState.\"NV\"'\n",
"\\item 'branch.\"Shreveport\"'\n",
"\\item 'residentialState.\"WV\"'\n",
"\\item 'branch.\"Spokane\"'\n",
"\\item 'branch.\"Gulfport\"'\n",
"\\item 'residentialState.\"VT\"'\n",
"\\end{enumerate*}\n"
],
"text/markdown": [
"1. 'installment'\n",
"2. 'loanAmount'\n",
"3. 'past_due_5'\n",
"4. 'term'\n",
"5. 'past_due_4'\n",
"6. 'past_due_3'\n",
"7. 'past_due_2'\n",
"8. 'past_due_1'\n",
"9. 'past_due'\n",
"10. 'branch.\"Bridgeport\"'\n",
"11. 'numTotalCreditLines'\n",
"12. 'branch.\"San Antonio\"'\n",
"13. 'annualIncome'\n",
"14. 'residentialState.\"NV\"'\n",
"15. 'branch.\"Shreveport\"'\n",
"16. 'residentialState.\"WV\"'\n",
"17. 'branch.\"Spokane\"'\n",
"18. 'branch.\"Gulfport\"'\n",
"19. 'residentialState.\"VT\"'\n",
"\n",
"\n"
],
"text/plain": [
" [1] \"installment\" \"loanAmount\" \n",
" [3] \"past_due_5\" \"term\" \n",
" [5] \"past_due_4\" \"past_due_3\" \n",
" [7] \"past_due_2\" \"past_due_1\" \n",
" [9] \"past_due\" \"branch.\\\"Bridgeport\\\"\" \n",
"[11] \"numTotalCreditLines\" \"branch.\\\"San Antonio\\\"\" \n",
"[13] \"annualIncome\" \"residentialState.\\\"NV\\\"\"\n",
"[15] \"branch.\\\"Shreveport\\\"\" \"residentialState.\\\"WV\\\"\"\n",
"[17] \"branch.\\\"Spokane\\\"\" \"branch.\\\"Gulfport\\\"\" \n",
"[19] \"residentialState.\\\"VT\\\"\""
]
},
"metadata": {},
"output_type": "display_data"
}
],
"outputs": [],
"source": [
"features <- select_features()\n",
"features"
@ -225,7 +130,7 @@
},
{
"cell_type": "code",
"execution_count": 5,
"execution_count": null,
"metadata": {
"collapsed": true
},
@ -253,7 +158,7 @@
},
{
"cell_type": "code",
"execution_count": 6,
"execution_count": null,
"metadata": {
"collapsed": true
},
@ -339,77 +244,11 @@
},
{
"cell_type": "code",
"execution_count": 7,
"execution_count": null,
"metadata": {
"collapsed": false
"collapsed": true
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"[1] \"Starting to train with logistic_reg\"\n",
"Elapsed time: 00:00:00.0377952\n",
"[1] \"Done training.\"\n",
"[1] \"Done writing predictions for evaluation of model.\"\n",
"Rows Read: 101, Total Rows Processed: 101, Total Chunk Time: 0.007 seconds \n",
"[1] \"Starting to train with fast_trees\"\n",
"[1] \"Done training.\"\n",
"Elapsed time: 00:00:00.0766733\n",
"[1] \"Done writing predictions for evaluation of model.\"\n",
"Rows Read: 101, Total Rows Processed: 101, Total Chunk Time: 0.007 seconds \n",
"[1] \"Starting to train with fast_forest\"\n",
"[1] \"Done training.\"\n",
"Elapsed time: 00:00:00.0455352\n",
"[1] \"Done writing predictions for evaluation of model.\"\n",
"Rows Read: 101, Total Rows Processed: 101, Total Chunk Time: 0.007 seconds \n",
"[1] \"Starting to train with fast_linear\"\n",
"Elapsed time: 00:00:00.0402667\n",
"[1] \"Done training.\"\n",
"[1] \"Done writing predictions for evaluation of model.\"\n",
"Rows Read: 101, Total Rows Processed: 101, Total Chunk Time: 0.007 seconds \n",
"[1] \"Starting to train with neural_net\"\n",
"[1] \"Done training.\"\n",
"Elapsed time: 00:00:00.0938715\n",
"[1] \"Done writing predictions for evaluation of model.\"\n",
"Rows Read: 101, Total Rows Processed: 101, Total Chunk Time: 0.010 seconds \n"
]
},
{
"data": {
"text/plain": [
"$model_name\n",
"[1] \"fast_linear\"\n",
"\n",
"$model\n",
"Call:\n",
"rxFastLinear(formula = model_formula, data = training_set, mlTransforms = ml_trans)\n",
"\n",
"SDCA (BinaryClassifierTrainer) for: charge_off~payment+past_due+remain_balance+loanAmount+interestRate+grade+term+installment+isJointApplication+purpose+residentialState+branch+annualIncome+yearsEmployment+homeOwnership+incomeVerified+creditScore+dtiRatio+revolvingBalance+revolvingUtilizationRate+numDelinquency2Years+numDerogatoryRec+numInquiries6Mon+lengthCreditHistory+numOpenCreditLines+numTotalCreditLines+numChargeoff1year+payment_1+payment_2+payment_3+payment_4+payment_5+past_due_1+past_due_2+past_due_3+past_due_4+past_due_5+remain_balance_1+remain_balance_2+remain_balance_3+remain_balance_4+remain_balance_5\n",
"Data: training_set (RxSqlServerData Data Source) \n",
"\n",
"$stats\n",
"$stats$auc\n",
"[1] 0.9975022\n",
"\n",
"$stats$accuracy\n",
"[1] 0.993602\n",
"\n",
"$stats$precision\n",
"[1] 0.8452381\n",
"\n",
"$stats$recall\n",
"[1] 0.8208092\n",
"\n",
"$stats$f1score\n",
"[1] 0.8328446\n",
"\n"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"outputs": [],
"source": [
"# train on MicrosoftML algorithms\n",
"ml_algs <- c(\"logistic_reg\", \"fast_trees\", \"fast_forest\", \"fast_linear\", \"neural_net\")\n",
@ -432,7 +271,7 @@
},
{
"cell_type": "code",
"execution_count": 8,
"execution_count": null,
"metadata": {
"collapsed": true
},
@ -456,7 +295,7 @@
"batch_score <- function (connection_string = sql_connection_string,\n",
" best_models_file = \"loan_chargeoff_best_model_10k.rdata\",\n",
" score_set = \"loan_chargeoff_score_10k\",\n",
" score_prediction = \"loan_chargeoff_prediction_10k\")\n",
" score_prediction = \"loan_chargeoff_prediction_10k_R\")\n",
"{\n",
" load(best_models_file)\n",
" if (!exists(\"best_model\"))\n",
@ -476,23 +315,24 @@
},
{
"cell_type": "code",
"execution_count": 9,
"execution_count": null,
"metadata": {
"collapsed": false
"collapsed": true
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"[1] \"Completed batch scoring.\"\n"
]
}
],
"outputs": [],
"source": [
"# call batch scoring function\n",
"batch_score()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": []
}
],
"metadata": {
@ -508,7 +348,7 @@
"mimetype": "text/x-r-source",
"name": "R",
"pygments_lexer": "r",
"version": "3.3.3"
"version": "3.4.1"
}
},
"nbformat": 4,

25
R/LoanChargeOff.rxproj Normal file
Просмотреть файл

@ -0,0 +1,25 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup Label="Globals">
<ProjectGuid>1c2df0a1-bc7c-4b4a-8483-e5769f768bb7</ProjectGuid>
</PropertyGroup>
<PropertyGroup>
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">15.0</VisualStudioVersion>
<Configuration Condition="'$(Configuration)' == ''">Debug</Configuration>
<Platform Condition="'$(Platform)' == ''">AnyCPU</Platform>
</PropertyGroup>
<PropertyGroup>
<StartupFile>Script.R</StartupFile>
</PropertyGroup>
<ProjectExtensions>
<VisualStudio>
<UserProperties />
</VisualStudio>
</ProjectExtensions>
<Target Name="Build" />
<Import Project="$(MSBuildUserExtensionsPath)\Microsoft\VisualStudio\v$(VisualStudioVersion)\RTVS\Rules\rtvs.rules.props" Condition="Exists('$(MSBuildUserExtensionsPath)\Microsoft\VisualStudio\v$(VisualStudioVersion)\RTVS\Rules\rtvs.rules.props')" />
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\RTVS\Rules\rtvs.rules.props" Condition="Exists('$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\RTVS\Rules\rtvs.rules.props') And !Exists('$(MSBuildUserExtensionsPath)\Microsoft\VisualStudio\v$(VisualStudioVersion)\RTVS\Rules\rtvs.rules.props')" />
<Import Project="$(MSBuildUserExtensionsPath)\Microsoft\VisualStudio\v$(VisualStudioVersion)\RTVS\Targets\Microsoft.R.targets" Condition="Exists('$(MSBuildUserExtensionsPath)\Microsoft\VisualStudio\v$(VisualStudioVersion)\RTVS\Targets\Microsoft.R.targets')" />
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\RTVS\Targets\Microsoft.R.targets" Condition="Exists('$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\RTVS\Targets\Microsoft.R.targets') And !Exists('$(MSBuildUserExtensionsPath)\Microsoft\VisualStudio\v$(VisualStudioVersion)\RTVS\Targets\Microsoft.R.targets')" />
<Import Project="LoanChargeOff.InMemory.Targets" Condition="Exists('LoanChargeOff.InMemory.Targets')" />
</Project>

25
R/LoanChargeOff.sln Normal file
Просмотреть файл

@ -0,0 +1,25 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.27004.2002
MinimumVisualStudioVersion = 10.0.40219.1
Project("{DA7A21FA-8162-4350-AD77-A8D1B671F3ED}") = "LoanChargeOff", "LoanChargeOff.rxproj", "{1C2DF0A1-BC7C-4B4A-8483-E5769F768BB7}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{1C2DF0A1-BC7C-4B4A-8483-E5769F768BB7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{1C2DF0A1-BC7C-4B4A-8483-E5769F768BB7}.Debug|Any CPU.Build.0 = Debug|Any CPU
{1C2DF0A1-BC7C-4B4A-8483-E5769F768BB7}.Release|Any CPU.ActiveCfg = Release|Any CPU
{1C2DF0A1-BC7C-4B4A-8483-E5769F768BB7}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {3EC3CE5B-9639-41E0-8A3C-C28D12780F81}
EndGlobalSection
EndGlobal

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

@ -15,10 +15,10 @@ library(MicrosoftML)
# 2. Modelling must have been completed
#
###########################################################################################################################################
batch_score <- function (connection_string = "Driver=SQL Server;Server=.;Database=LoanChargeOff;UID=<sql username>;PWD=<sql password>",
batch_score <- function (connection_string = "Driver=SQL Server;Server=.;Database=LoanChargeOff_R;Trusted_Connection=True",
best_models_file = "loan_chargeoff_best_model_10k.rdata",
score_set = "loan_chargeoff_score_10k",
score_prediction = "loan_chargeoff_prediction_10k")
score_prediction = "loan_chargeoff_prediction_10k_R")
{
load(best_models_file)
if (!exists("best_model"))

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

@ -13,7 +13,7 @@ library(MicrosoftML)
# created and dataset imported (it's already been run for 10k loans data set)
#
###########################################################################################################################################
select_features <- function(connection_string = "Driver=SQL Server;Server=.;Database=LoanChargeOff;UID=<sql username>;PWD=<sql password>",
select_features <- function(connection_string = "Driver=SQL Server;Server=.;Database=LoanChargeOff_R;Trusted_Connection=True",
train_set = "loan_chargeoff_train_10k",
test_set = "loan_chargeoff_test_10k")
{

Двоичные данные
R/loan_chargeoff_best_model_10k.rdata Normal file

Двоичный файл не отображается.

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

@ -44,7 +44,7 @@ train_model <- function(model_name = "logistic_regression",
train_set = "loan_chargeoff_train_10k",
test_set = "loan_chargeoff_test_10k",
score_set = "loan_chargeoff_eval_score_10k",
connection_string = "Driver=SQL Server;Server=.;Database=LoanChargeOff;UID=<sql username>;PWD=<sql password>"
connection_string = "Driver=SQL Server;Server=.;Database=LoanChargeOff_R;Trusted_Connection=True"
)
{

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

@ -0,0 +1,284 @@
[CmdletBinding()]
param(
[parameter(Mandatory=$true, Position=1)]
[string]$ServerName,
[parameter(Mandatory=$true, Position=2)]
[string]$SolutionName,
[parameter(Mandatory=$true, Position=3)]
[string]$InstallPy,
[parameter(Mandatory=$true, Position=4)]
[string]$InstallR,
[parameter(Mandatory=$true, Position=5)]
[string]$Prompt
)
$Prompt = 'N'
###$ServerName = if ($Prompt -eq 'Y') {Read-Host -Prompt "Enter SQL Server Name Or SQL InstanceName you are installing on"} else {$si}
WRITE-HOST " ServerName set to $ServerName"
$db = if ($Prompt -eq 'Y') {Read-Host -Prompt "Enter Desired Database Base Name"} else {$SolutionName}
$dataList = ( "loan_info_10k", "member_info_10k", "payments_info_10k")
##########################################################################
# Create Database and BaseTables
#########################################################################
####################################################################
# Check to see If SQL Version is at least SQL 2017 and Not SQL Express
####################################################################
$query =
"select
case
when
cast(left(cast(serverproperty('productversion') as varchar), 4) as numeric(4,2)) >= 14
and CAST(SERVERPROPERTY ('edition') as varchar) Not like 'Express%'
then 'Yes'
else 'No' end as 'isSQL17'"
$isCompatible = Invoke-Sqlcmd -ServerInstance $ServerName -Database Master -Query $query
$isCompatible = $isCompatible.Item(0)
if ($isCompatible -eq 'Yes' -and $InstallPy -eq 'Yes') {
Write-Host " This Version of SQL is Compatible with SQL Py "
## Create Py Database
Write-Host " Creating SQL Database for Py "
Write-Host -ForeGroundColor 'cyan' (" Using $ServerName SQL Instance")
## Create PY Server DB
$dbName = $db + "_Py"
$SqlParameters = @("dbName=$dbName")
$CreateSQLDB = "$ScriptPath\CreateDatabase.sql"
$CreateSQLObjects = "$ScriptPath\CreateSQLObjectsPy.sql"
Write-Host -ForeGroundColor 'cyan' (" Calling Script to create the $dbName database")
invoke-sqlcmd -inputfile $CreateSQLDB -serverinstance $ServerName -database master -Variable $SqlParameters
Write-Host -ForeGroundColor 'cyan' (" SQLServerDB $dbName Created")
invoke-sqlcmd "USE $dbName;"
Write-Host -ForeGroundColor 'cyan' (" Calling Script to create the objects in the $dbName database")
invoke-sqlcmd -inputfile $CreateSQLObjects -serverinstance $ServerName -database $dbName
Write-Host -ForeGroundColor 'cyan' (" SQLServerObjects Created in $dbName Database")
$OdbcName = "obdc" + $dbname
## Create ODBC Connection for PowerBI to Use
Add-OdbcDsn -Name $OdbcName -DriverName "ODBC Driver 13 for SQL Server" -DsnType 'System' -Platform '64-bit' -SetPropertyValue @("Server=$ServerName", "Trusted_Connection=Yes", "Database=$dbName") -ErrorAction SilentlyContinue -PassThru
}
else
{
if ($isCompatible -eq 'Yes' -and $InstallPy -eq 'Yes') {"This Version of SQL is not compatible with Py , Py Code and DB's will not be Created "}
else {" There is not a py version of this solution"}
}
If ($InstallR -eq 'Yes')
{
Write-Host " Creating SQL Database for R "
Write-Host -ForeGroundColor 'cyan' (" Using $ServerName SQL Instance")
$dbName = $db + "_R"
## Create RServer DB
$SqlParameters = @("dbName=$dbName")
$CreateSQLDB = "$ScriptPath\CreateDatabase.sql"
$CreateSQLObjects = "$ScriptPath\CreateSQLObjectsR.sql"
Write-Host -ForeGroundColor 'cyan' (" Calling Script to create the $dbName database")
invoke-sqlcmd -inputfile $CreateSQLDB -serverinstance $ServerName -database master -Variable $SqlParameters
Write-Host -ForeGroundColor 'cyan' (" SQLServerDB $dbName Created")
invoke-sqlcmd "USE $dbName;"
Write-Host -ForeGroundColor 'cyan' (" Calling Script to create the objects in the $dbName database")
invoke-sqlcmd -inputfile $CreateSQLObjects -serverinstance $ServerName -database $dbName
Write-Host -ForeGroundColor 'cyan' (" SQLServerObjects Created in $dbName Database")
###Configure Database for R
Write-Host "
Configuring $SolutionName Solution for R
"
$dbName = $db + "_R"
## Create ODBC Connection for PowerBI to Use
$OdbcName = "obdc" + $dbname
## Create ODBC Connection for PowerBI to Use
Add-OdbcDsn -Name $OdbcName -DriverName "ODBC Driver 13 for SQL Server" -DsnType 'System' -Platform '64-bit' -SetPropertyValue @("Server=$ServerName", "Trusted_Connection=Yes", "Database=$dbName") -ErrorAction SilentlyContinue -PassThru
##########################################################################
# Deployment Pipeline
##########################################################################
$RStart = Get-Date
try
{
Write-Host -ForeGroundColor 'cyan' (" Import CSV File(s). This Should take about 30 Seconds Per File")
$qry = "BULK INSERT loan_info_10k FROM 'C:\Solutions\LoanChargeOff\Data\loan_info_10k.txt'"
SqlServer\Invoke-Sqlcmd -ServerInstance LocalHost -Database $dbName -Query $qry -ConnectionTimeout 0 -QueryTimeout 0
$qry = "BULK INSERT member_info_10k FROM 'C:\Solutions\LoanChargeOff\Data\member_info_10k.txt'"
SqlServer\Invoke-Sqlcmd -ServerInstance LocalHost -Database $dbName -Query $qry -ConnectionTimeout 0 -QueryTimeout 0
$qry = "BULK INSERT payments_info_10k FROM 'C:\Solutions\LoanChargeOff\Data\payments_info_10k.txt'"
SqlServer\Invoke-Sqlcmd -ServerInstance LocalHost -Database $dbName -Query $qry -ConnectionTimeout 0 -QueryTimeout 0
# $qry = "BULK INSERT loan_info_100k FROM 'C:\Solutions\LoanChargeOff\Data\loan_info_100k.txt'"
# SqlServer\Invoke-Sqlcmd -ServerInstance LocalHost -Database $dbName -Query $qry -ConnectionTimeout 0 -QueryTimeout 0
# $qry = "BULK INSERT member_info_100k FROM 'C:\Solutions\LoanChargeOff\Data\member_info_100k.txt'"
# SqlServer\Invoke-Sqlcmd -ServerInstance LocalHost -Database $dbName -Query $qry -ConnectionTimeout 0 -QueryTimeout 0
# $qry = "BULK INSERT payments_info_100k FROM 'C:\Solutions\LoanChargeOff\Data\payments_info_100k.txt'"
# SqlServer\Invoke-Sqlcmd -ServerInstance LocalHost -Database $dbName -Query $qry -ConnectionTimeout 0 -QueryTimeout 0
Write-Host -ForeGroundColor 'cyan' (" Data has been Loaded from Csv Files")
# upload csv files into SQL tables
foreach ($dataFile in $dataList)
{
#$destination = $SolutionData + $dataFile + ".csv"
#$destination = "'"+ $SolutionData + $dataFile + ".txt'"
#$tableName = $DBName + ".dbo." + $dataFile
#$tableSchema = $dataPath + "\" + $dataFile + ".xml"
#$dataSet = Import-Csv $destination
#Write-Host -ForegroundColor 'cyan' (" Loading $dataFile.csv into SQL Table")
##Write-SqlTableData -InputData $dataSet -DatabaseName $dbName -Force -Passthru -SchemaName dbo -ServerInstance $ServerName -TableName $dataFile
##invoke-expression "bcp $dataFile in $destination -S $ServerName -d $dbName -T -k -c"
#invoke-expression "bcp $tableName in $destination -S $ServerName -f $tableSchema -F 2 -C "RAW" -b 100000 -T"
#$qry = "BULK INSERT $tableName FROM $destination"
#SqlServer\Invoke-Sqlcmd -ServerInstance LocalHost -Database $dbName -Query $qry -ConnectionTimeout 0 -QueryTimeout 0
#Write-Host -ForeGroundColor 'cyan' (" $datafile table loaded from CSV File(s).")
}
}
catch
{
Write-Host -ForegroundColor DarkYellow "Exception in populating database tables:"
Write-Host -ForegroundColor Red $Error[0].Exception
throw
}
Write-Host -ForeGroundColor 'cyan' (" Finished loading .csv File(s).")
Write-Host -ForeGroundColor 'Cyan' (" Training Model and Scoring Data...")
$query = "EXEC Initial_Run_Once_R"
#SqlServer\Invoke-Sqlcmd -ServerInstance $ServerName -Database $dbName -Query $query -ConnectionTimeout 0 -QueryTimeout 0
SqlServer\Invoke-Sqlcmd -ServerInstance LocalHost -Database $dbName -Query $query -ConnectionTimeout 0 -QueryTimeout 0
$Rend = Get-Date
$Duration = New-TimeSpan -Start $RStart -End $Rend
Write-Host -ForegroundColor 'green'(" R Server Configured in $Duration")
}
ELSE
{Write-Host -ForegroundColor 'Green' "There is not a R Version for this Solution so R will not be Installed"}
###Conifgure Database for Py
if ($isCompatible -eq 'Yes'-and $InstallPy -eq 'Yes')
{
$PyStart = get-date
Write-Host "
Configuring $SolutionName Solution for Py
# "
$dbname = $db + "_Py"
##########################################################################
# Deployment Pipeline Py
##########################################################################
try
{
Write-Host -ForeGroundColor 'cyan' (" Import CSV File(s). This Should take about 30 Seconds Per File")
#$dataList = "LengthOfStay"
# upload csv files into SQL tables
foreach ($dataFile in $dataList)
{
$destination = $SolutionData + $dataFile + ".csv"
$tableName = $DBName + ".dbo." + $dataFile
$tableSchema = $dataPath + "\" + $dataFile + ".xml"
$dataSet = Import-Csv $destination
Write-Host -ForegroundColor 'cyan' (" Loading $dataFile.csv into SQL Table")
Write-SqlTableData -InputData $dataSet -DatabaseName $dbName -Force -Passthru -SchemaName dbo -ServerInstance $ServerName -TableName $dataFile
Write-Host -ForeGroundColor 'cyan' (" $datafile table loaded from CSV File(s).")
}
}
catch
{
Write-Host -ForegroundColor DarkYellow "Exception in populating database tables:"
Write-Host -ForegroundColor Red $Error[0].Exception
throw
}
Write-Host -ForeGroundColor 'cyan' (" Finished loading .csv File(s).")
Write-Host -ForeGroundColor 'Cyan' (" Training Model and Scoring Data...")
$query = "EXEC Inital_Run_Once_Py"
SqlServer\Invoke-Sqlcmd -ServerInstance LocalHost -Database $dbName -Query $query -ConnectionTimeout 0 -QueryTimeout 0
$Pyend = Get-Date
$Duration = New-TimeSpan -Start $PyStart -End $Pyend
Write-Host -ForegroundColor 'green'(" Py Server Configured in $Duration")
}

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

@ -0,0 +1,142 @@
BEGIN
DECLARE
@DbName VARCHAR(400) = N'$(dbName)',
@ServerName varchar(100) = (SELECT CAST(SERVERPROPERTY('ServerName') as Varchar)),
@InstanceName varchar(100) = (SELECT CAST(SERVERPROPERTY('InstanceName') as Varchar)),
@UI varchar(100),
@Qry VARCHAR(MAX)
----Create Needed SQLRUsergroup Name ,
----if Default Instance UI = {ServerName}\SQLRUserGroup
----if Named Instance {ServerName}\SQLRUserGroup{InstanceName}
If @InstanceName is null
BEGIN
SET @UI = @ServerName + '\SQLRUserGroup'
END
If @InstanceName is Not null
BEGIN
SET @UI = @ServerName + '\SQLRUserGroup' + @InstanceName
END
SET @Qry =
('
EXEC msdb.dbo.sp_delete_database_backuphistory @database_name = N''<DBName>''
USE [master]
ALTER DATABASE <DBName> SET SINGLE_USER WITH ROLLBACK IMMEDIATE
USE [master]
DROP DATABASE <DBName>
')
--If DB Already Exists , Drop it and recreate it
IF EXISTS(select * from sys.databases where name = @DbName)
BEGIN
SET @Qry = (REPLACE(@Qry,'<dbName>',@DbName) )
EXEC (@Qry)
END
DECLARE @Query VARCHAR(MAX)=''
---Find Default Database File Path and Create DB there
DECLARE @DbFilePath VARCHAR(400) = (SELECT top 1 LEFT(physical_name, (LEN(physical_name) - CHARINDEX('\',REVERSE(physical_name)))) + '\' as BasePath FROM sys.master_files WHERE type_desc = 'ROWS')
--Find Default Log File Path and Create Log there
DECLARE @LogFilePath VARCHAR(400) = (SELECT top 1 LEFT(physical_name, (LEN(physical_name) - CHARINDEX('\',REVERSE(physical_name)))) + '\' as BasePath FROM sys.master_files WHERE type_desc = 'LOG')
IF NOT EXISTS(select * from sys.databases where name = @DbName)
BEGIN
SET @Query = @Query + 'CREATE DATABASE '+@DbName +' ON PRIMARY '
SET @Query = @Query + '( NAME = '''+@DbName +''', FILENAME = '''+@DbFilePath+@DbName +'.mdf'' , SIZE = 73728KB , MAXSIZE = UNLIMITED, FILEGROWTH = 1024KB ) '
SET @Query = @Query + ' LOG ON '
SET @Query = @Query + '( NAME = '''+@DbName +'_log'', FILENAME = '''+@LogFilePath+@DbName +'_log.ldf'' , SIZE = 1024KB , MAXSIZE = 2048GB , FILEGROWTH = 1024KB)'
exec(@query)
END
DECLARE @Alter VARCHAR(MAX)
SET @Alter =
(
'ALTER DATABASE <db> SET COMPATIBILITY_LEVEL = 130
IF (1 = FULLTEXTSERVICEPROPERTY(''IsFullTextInstalled''))
begin
EXEC <db>.[dbo].[sp_fulltext_database] @action = ''enable''
end
ALTER DATABASE <db> SET ANSI_NULL_DEFAULT OFF
ALTER DATABASE <db> SET ANSI_NULLS OFF
ALTER DATABASE <db> SET ANSI_PADDING OFF
ALTER DATABASE <db> SET ANSI_WARNINGS OFF
ALTER DATABASE <db> SET ARITHABORT OFF
ALTER DATABASE <db> SET AUTO_CLOSE OFF
ALTER DATABASE <db> SET AUTO_SHRINK OFF
ALTER DATABASE <db> SET AUTO_UPDATE_STATISTICS ON
ALTER DATABASE <db> SET CURSOR_CLOSE_ON_COMMIT OFF
ALTER DATABASE <db> SET CURSOR_DEFAULT GLOBAL
ALTER DATABASE <db> SET CONCAT_NULL_YIELDS_NULL OFF
ALTER DATABASE <db> SET NUMERIC_ROUNDABORT OFF
ALTER DATABASE <db> SET QUOTED_IDENTIFIER OFF
ALTER DATABASE <db> SET RECURSIVE_TRIGGERS OFF
ALTER DATABASE <db> SET ENABLE_BROKER
ALTER DATABASE <db> SET AUTO_UPDATE_STATISTICS_ASYNC OFF
ALTER DATABASE <db> SET DATE_CORRELATION_OPTIMIZATION OFF
ALTER DATABASE <db> SET TRUSTWORTHY OFF
ALTER DATABASE <db> SET ALLOW_SNAPSHOT_ISOLATION OFF
ALTER DATABASE <db> SET PARAMETERIZATION SIMPLE
ALTER DATABASE <db> SET READ_COMMITTED_SNAPSHOT OFF
ALTER DATABASE <db> SET HONOR_BROKER_PRIORITY OFF
ALTER DATABASE <db> SET RECOVERY FULL
ALTER DATABASE <db> SET MULTI_USER
ALTER DATABASE <db> SET PAGE_VERIFY CHECKSUM
ALTER DATABASE <db> SET DB_CHAINING OFF
ALTER DATABASE <db> SET FILESTREAM( NON_TRANSACTED_ACCESS = OFF )
ALTER DATABASE <db> SET TARGET_RECOVERY_TIME = 60 SECONDS
ALTER DATABASE <db> SET DELAYED_DURABILITY = DISABLED
EXEC sys.sp_db_vardecimal_storage_format N''<db>'', N''ON''
ALTER DATABASE <db> SET QUERY_STORE = OFF
ALTER DATABASE <db> SET READ_WRITE'
)
SET @Alter = (REPLACE(@Alter,'<db>',@DbName))
EXEC (@Alter)
----CREATE USER SQLRUserGroup on SQL Server
SET @Qry =
'
IF NOT EXISTS (SELECT name FROM master.sys.server_principals where name = ''<ui>'')
BEGIN CREATE LOGIN [<ui>] FROM WINDOWS WITH DEFAULT_DATABASE=[master], DEFAULT_LANGUAGE=[us_english] END
'
SET @Qry = REPLACE(@qry,'<ui>', @ui)
EXEC (@Qry)
--SELECT @Qry
----Give SQLRUserGroup Rights To Database(s)
SET @Qry =
'
USE [<dbName>]
CREATE USER [<ui>] FOR LOGIN [<ui>]
ALTER USER [<ui>] WITH DEFAULT_SCHEMA=NULL
ALTER AUTHORIZATION ON SCHEMA::[db_datareader] TO [<ui>]
ALTER AUTHORIZATION ON SCHEMA::[db_datawriter] TO [<ui>]
ALTER AUTHORIZATION ON SCHEMA::[db_ddladmin] TO [<ui>]
'
SET @Qry = REPLACE(REPLACE(@qry,'<ui>', @ui),'<dbName>',@DbName)
EXEC (@Qry)
--SELECT @Qry
END

Двоичные данные
Resources/ActionScripts/CreateSQLObjectsR.sql Normal file

Двоичный файл не отображается.

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

@ -0,0 +1,6 @@
[InternetShortcut]
URL=https://microsoft.github.io/r-server-loan-chargeoff/Typical.html?path=cig
IDList=
HotKey=0
[{000214A0-0000-0000-C000-000000000046}]
Prop3=19,11

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

@ -0,0 +1,288 @@
[CmdletBinding()]
param(
[parameter(Mandatory=$True, Position=1)]
[ValidateNotNullOrEmpty()]
[string]$serverName,
[parameter(Mandatory=$True, Position=2)]
[ValidateNotNullOrEmpty()]
[string]$username,
[parameter(Mandatory=$True, Position=3)]
[ValidateNotNullOrEmpty()]
[string]$password,
[parameter(Mandatory=$false, Position=4)]
[ValidateNotNullOrEmpty()]
[string]$baseurl,
[parameter(Mandatory=$false, Position=5)]
[ValidateNotNullOrEmpty()]
[string]$Prompt
)
$startTime = Get-Date
#$Prompt= if ($Prompt -match '^y(es)?$') {'Y'} else {'N'}
$Prompt = 'N'
if($baseurl -eq $null) {$isStandalone = 'Y'} ELSE {$isStandalone = 'N'}
#$isStandAlone = 'N'
##Change Values here for Different Solutions
$SolutionName = "LoanChargeOff"
$SolutionFullName = "r-server-loan-chargeoff"
$JupyterNotebook = "LoanChargeOff.ipynb"
$Shortcut = "LoanChargeOffHelp.url"
### DON'T FORGET TO CHANGE TO MASTER LATER...
$Branch = "Dev"
$InstallR = 'Yes' ## If Solution has a R Version this should be 'Yes' Else 'No'
$InstallPy = 'No' ## If Solution has a Py Version this should be 'Yes' Else 'No'
$SampleWeb = 'No' ## If Solution has a Sample Website this should be 'Yes' Else 'No'
$EnableFileStream = 'No' ## If Solution Requires FileStream DB this should be 'Yes' Else 'No'
$Prompt = 'N'
$setupLog = "c:\tmp\setup_log.txt"
Start-Transcript -Path $setupLog -Append
$startTime = Get-Date
Write-Host -ForegroundColor 'Green' " Start time:" $startTime
###These probably don't need to change , but make sure files are placed in the correct directory structure
$solutionTemplateName = "Solutions"
$solutionTemplatePath = "C:\" + $solutionTemplateName
$checkoutDir = $SolutionName
$SolutionPath = $solutionTemplatePath + '\' + $checkoutDir
$desktop = "C:\Users\Public\Desktop\"
$scriptPath = $SolutionPath + "\Resources\ActionScripts\"
$SolutionData = $SolutionPath + "\Data\"
####$Query = "SELECT SERVERPROPERTY('ServerName')"
##$si = invoke-sqlcmd -Query $Query
##$si = $si.Item(0)
###$serverName = if($serverName -eq $null) {$si}
##WRITE-HOST " ServerName set to $ServerName"
##########################################################################
#Clone Data from GIT
##########################################################################
$clone = "git clone --branch $Branch --single-branch https://github.com/Microsoft/$SolutionFullName $solutionPath"
if (Test-Path $SolutionPath) { Write-Host " Solution has already been cloned"}
ELSE {Invoke-Expression $clone}
If ($InstalR -eq 'Yes')
{
Write-Host -ForeGroundColor magenta "Installing R Packages"
Set-Location "C:\Solutions\$SolutionName\Resources\ActionScripts\"
# install R Packages
Rscript install.R
}
if ($isStandAlone -eq 'N')
{
cd $SolutionData
# List of data files to be downloaded
$dataList = "loan_info_10k", "member_info_10k", "payments_info_10k", "loan_info_100k", "member_info_100k", "payments_info_100k", "loan_info_1m", "member_info_1m", "payments_info_1m"
$dataExtn = ".csv"
$hashExtn = ".hash"
foreach ($dataFile in $dataList)
{
$down = $baseurl + '/' + $dataFile + $dataExtn
Write-Host -ForeGroundColor 'magenta' "Downloading file $down..."
Start-BitsTransfer -Source $down
}
}
#################################################################
##DSVM Does not have SQLServer Powershell Module Install or Update
#################################################################
Write-Host " Installing SQLServer Power Shell Module or Updating to latest "
if (Get-Module -ListAvailable -Name SQLServer) {Update-Module -Name "SQLServer"}
else
{
Install-Module -Name SQLServer -Scope AllUsers -AllowClobber -Force
Import-Module -Name SQLServer
}
## if FileStreamDB is Required Alter Firewall ports for 139 and 445
if ($EnableFileStream -eq 'Yes')
{
netsh advfirewall firewall add rule name="Open Port 139" dir=in action=allow protocol=TCP localport=139
netsh advfirewall firewall add rule name="Open Port 445" dir=in action=allow protocol=TCP localport=445
Write-Host -ForeGroundColor cyan " Firewall as been opened for filestream access..."
}
If ($EnableFileStream -eq 'Yes')
{
Set-Location "C:\Program Files\Microsoft\ML Server\PYTHON_SERVER\python.exe"
.\setup.py install
Write-Host -ForeGroundColor cyan " Py Instal has been updated to latest version..."
}
############################################################################################
#Configure SQL to Run our Solutions
############################################################################################
#Write-Host -ForegroundColor 'Cyan' " Switching SQL Server to Mixed Mode"
### Change Authentication From Windows Auth to Mixed Mode
Invoke-Sqlcmd -Query "EXEC xp_instance_regwrite N'HKEY_LOCAL_MACHINE', N'Software\Microsoft\MSSQLServer\MSSQLServer', N'LoginMode', REG_DWORD, 2;" -ServerInstance "LocalHost"
Write-Host -ForeGroundColor 'cyan' " Configuring SQL to allow running of External Scripts "
### Allow Running of External Scripts , this is to allow R Services to Connect to SQL
Invoke-Sqlcmd -Query "EXEC sp_configure 'external scripts enabled', 1"
### Force Change in SQL Policy on External Scripts
Invoke-Sqlcmd -Query "RECONFIGURE WITH OVERRIDE"
Write-Host -ForeGroundColor 'cyan' " SQL Server Configured to allow running of External Scripts "
### Enable FileStreamDB if Required by Solution
if ($EnableFileStream -eq 'Yes')
{
# Enable FILESTREAM
$instance = "MSSQLSERVER"
$wmi = Get-WmiObject -Namespace "ROOT\Microsoft\SqlServer\ComputerManagement14" -Class FilestreamSettings | where-object {$_.InstanceName -eq $instance}
$wmi.EnableFilestream(3, $instance)
Stop-Service "MSSQ*" -Force
Start-Service "MSSQ*"
Set-ExecutionPolicy Unrestricted
#Import-Module "sqlps" -DisableNameChecking
Invoke-Sqlcmd "EXEC sp_configure filestream_access_level, 2"
Invoke-Sqlcmd "RECONFIGURE WITH OVERRIDE"
Stop-Service "MSSQ*"
Start-Service "MSSQ*"
}
ELSE
{
Write-Host -ForeGroundColor 'cyan' " Restarting SQL Services "
### Changes Above Require Services to be cycled to take effect
### Stop the SQL Service and Launchpad wild cards are used to account for named instances
Restart-Service -Name "MSSQ*" -Force
}
### Start the SQL Service
#Start-Service -Name "MSSQ*"
#Write-Host -ForegroundColor 'Cyan' " SQL Services Restarted"
$Query = "CREATE LOGIN $username WITH PASSWORD=N'$password', DEFAULT_DATABASE=[master], CHECK_EXPIRATION=OFF, CHECK_POLICY=OFF"
Invoke-Sqlcmd -Query $Query -ErrorAction SilentlyContinue
$Query = "ALTER SERVER ROLE [sysadmin] ADD MEMBER $username"
Invoke-Sqlcmd -Query $Query -ErrorAction SilentlyContinue
##Unzip Data Files
#Expand-Archive -LiteralPath "$SolutionData\10kRecords.zip" -DestinationPath $SolutionData -Force
####Run Configure SQL to Create Databases and Populate with needed Data
$ConfigureSql = "C:\Solutions\$SolutionName\Resources\ActionScripts\ConfigureSQL.ps1 $ServerName $SolutionName $InstallPy $InstallR $Prompt"
Invoke-Expression $ConfigureSQL
Write-Host -ForegroundColor 'Cyan' " Done with configuration changes to SQL Server"
Write-Host -ForeGroundColor cyan " Installing latest Power BI..."
# Download PowerBI Desktop installer
Start-BitsTransfer -Source "https://go.microsoft.com/fwlink/?LinkId=521662&clcid=0x409" -Destination powerbi-desktop.msi
# Silently install PowerBI Desktop
msiexec.exe /i powerbi-desktop.msi /qn /norestart ACCEPT_EULA=1
if (!$?) {
Write-Host -ForeGroundColor Red " Error installing Power BI Desktop. Please install latest Power BI manually."
}
##Create Shortcuts and Autostart Help File
Copy-Item "$ScriptPath\$Shortcut" C:\Users\Public\Desktop\
Copy-Item "$ScriptPath\$Shortcut" "C:\ProgramData\Microsoft\Windows\Start Menu\Programs\StartUp\"
Write-Host -ForeGroundColor cyan " Help Files Copied to Desktop"
$WsShell = New-Object -ComObject WScript.Shell
$shortcut = $WsShell.CreateShortcut($desktop + $checkoutDir + ".lnk")
$shortcut.TargetPath = $solutionPath
$shortcut.Save()
## copy Jupyter Notebook files
# Move-Item $SolutionPath\R\$JupyterNotebook c:\tmp\
# sed -i "s/XXYOURSQLPW/$password/g" c:\tmp\$JupyterNotebook
# sed -i "s/XXYOURSQLUSER/$username/g" c:\tmp\$JupyterNotebook
# Move-Item c:\tmp\$JupyterNotebook $SolutionPath\R\
#cp $SolutionData*.csv c:\dsvm\notebooks
# substitute real username and password in notebook file
#XXXXXXXXXXChange to NEw NotebookNameXXXXXXXXXXXXXXXXXX#
if ($InstallPy -eq "Yes")
{
# Move-Item $SolutionPath\Python\$JupyterNotebook c:\tmp\
# sed -i "s/XXYOURSQLPW/$password/g" c:\tmp\$JupyterNotebook
# sed -i "s/XXYOURSQLUSER/$username/g" c:\tmp\$JupyterNotebook
# Move-Item c:\tmp\$JupyterNotebook $SolutionPath\Python\
}
# install modules for sample website
if($SampleWeb -eq "Yes")
{
cd $SolutionPath\Website\
npm install
Move-Item $SolutionPath\Website\server.js c:\tmp\
sed -i "s/XXYOURSQLPW/$password/g" c:\tmp\server.js
sed -i "s/XXYOURSQLUSER/$username/g" c:\tmp\server.js
Move-Item c:\tmp\server.js $SolutionPath\Website
}
$endTime = Get-Date
Write-Host -foregroundcolor 'green'(" $SolutionFullName Workflow Finished Successfully!")
$Duration = New-TimeSpan -Start $StartTime -End $EndTime
Write-Host -ForegroundColor 'green'(" Total Deployment Time = $Duration")
Stop-Transcript
##Launch HelpURL
Start-Process "https://microsoft.github.io/$SolutionFullName/Typical.html"
## Close Powershell
Exit-PSHostProcess
EXIT

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

@ -1,172 +0,0 @@
<#
.SYNOPSIS
Powershell script for setting up the solution template.
.DESCRIPTION
This script checks out the solution from github and deploys it to SQL Server on the local Data Science VM (DSVM).
.WARNING: This script is only meant to be run from the solution template deployment process.
.PARAMETER serverName
Name of the server with SQL Server with R Services (this is the DSVM server)
.PARAMETER baseurl
url from which to download data files
.PARAMETER username
login username for the server
.PARAMETER password
login password for the server
.PARAMETER sqlUsername
User to create in SQL Server
.PARAMETER sqlPassword
Password for the SQL User
#>
[CmdletBinding()]
param(
[parameter(Mandatory=$true, Position=1, ParameterSetName = "LCR")]
[ValidateNotNullOrEmpty()]
[string]$serverName,
[parameter(Mandatory=$true, Position=2, ParameterSetName = "LCR")]
[ValidateNotNullOrEmpty()]
[string]$baseurl,
[parameter(Mandatory=$true, Position=3, ParameterSetName = "LCR")]
[ValidateNotNullOrEmpty()]
[string]$username,
[parameter(Mandatory=$true, Position=4, ParameterSetName = "LCR")]
[ValidateNotNullOrEmpty()]
[string]$password,
[parameter(Mandatory=$true, Position=5, ParameterSetName = "LCR")]
[ValidateNotNullOrEmpty()]
[string]$sqlUsername,
[parameter(Mandatory=$true, Position=6, ParameterSetName = "LCR")]
[ValidateNotNullOrEmpty()]
[string]$sqlPassword
)
$startTime= Get-Date
Write-Host "Start time for setup is:" $startTime
$originalLocation = Get-Location
# This is the directory for the data/code download
$solutionTemplateSetupDir = "LoanChargeOffSolution"
$solutionTemplateSetupPath = "D:\" + $solutionTemplateSetupDir
$dataDir = "Data"
$dataDirPath = $solutionTemplateSetupPath + "\" + $dataDir
$reportsDir = "Reports"
$reportsDirPath = $solutionTemplateSetupPath + "\" + $reportsDir
New-Item -Path "D:\" -Name $solutionTemplateSetupDir -ItemType directory -force
New-Item -Path $solutionTemplateSetupPath -Name $dataDir -ItemType directory -force
New-Item -Path $solutionTemplateSetupPath -Name $reportsDir -ItemType directory -force
$checkoutDir = "Source"
$setupLog = $solutionTemplateSetupPath + "\setup_log.txt"
Start-Transcript -Path $setupLog -Append
cd $dataDirPath
# List of data files to be downloaded
$dataList = "loan_info_10k", "member_info_10k", "payments_info_10k", "loan_info_100k", "member_info_100k", "payments_info_100k", "loan_info_1m", "member_info_1m", "payments_info_1m"
$dataExtn = ".csv"
$hashExtn = ".hash"
foreach ($dataFile in $dataList)
{
$down = $baseurl + '/' + $dataFile + $dataExtn
Write-Host -ForeGroundColor 'magenta' "Downloading file $down..."
Start-BitsTransfer -Source $down
}
# Download Power BI Reports
cd $reportsDirPath
$reportsList = "Landscape.pbix", "Portrait.pbix"
foreach ($report in $reportsList)
{
$down = $baseurl + "/dashboards/TryItNow/" + $report
Write-Host -ForeGroundColor 'magenta' "Downloading report $down..."
Start-BitsTransfer -Source $down -Destination $report
}
#checkout setup scripts/code from github
cd $solutionTemplateSetupPath
if (Test-Path $checkoutDir)
{
Remove-Item $checkoutDir -Force -Recurse
}
git clone -n https://github.com/Microsoft/r-server-loan-chargeoff $checkoutDir
cd $checkoutDir
git config core.sparsecheckout true
echo "/*`r`n!HDI`r`n!Resources" | out-file -encoding ascii .git/info/sparse-checkout
git checkout master
$sqlsolutionCodePath = $solutionTemplateSetupPath + "\" + $checkoutDir + "\SQLR"
$helpShortCutFilePath = $sqlsolutionCodePath + "\LoanChargeOffHelp.url"
cd $sqlsolutionCodePath
# make sure the hashes match for data files
Write-Host -ForeGroundColor 'magenta' "Checking integrity of downloaded files..."
foreach ($dataFile in $dataList)
{
$dataFileHash = Get-FileHash ($dataDirPath + "\" + $dataFile + $dataExtn) -Algorithm SHA512
$storedHash = Get-Content ($dataFile + $hashExtn)
if ($dataFileHash.Hash -ne $storedHash)
{
Write-Error "Data file $dataFile has been corrupted. Please try again."
throw
}
}
foreach ($report in $reportsList)
{
$fileHash = Get-FileHash ($reportsDirPath + "\" + $report) -Algorithm SHA512
$storedHash = Get-Content ($report + $hashExtn)
if ($fileHash.Hash -ne $storedHash)
{
Write-Error "Report file $report has been corrupted. Please try again."
throw
}
}
Write-Host -ForeGroundColor 'magenta' "File integrity check successful."
# Start the script for DB creation. Due to privilege issues with SYSTEM user (the user that runs the
# extension script), we use ps-remoting to login as admin use and run the DB creation scripts
$passwords = $password | ConvertTo-SecureString -AsPlainText -Force
$credential = New-Object System.Management.Automation.PSCredential("$serverName\$username", $passwords)
$command1 = "runDB.ps1"
$command2 ="setupHelp.ps1"
Enable-PSRemoting -Force
Invoke-Command -Credential $credential -ComputerName $serverName -FilePath $command1 -ArgumentList $dataDirPath, $sqlsolutionCodePath, $sqlUsername, $sqlPassword
Invoke-Command -Credential $credential -ComputerName $serverName -FilePath $command2 -ArgumentList $helpShortCutFilePath, $solutionTemplateSetupPath
Disable-PSRemoting -Force
Write-Host -ForeGroundColor magenta "Installing latest Power BI..."
# Download PowerBI Desktop installer
Start-BitsTransfer -Source "https://go.microsoft.com/fwlink/?LinkId=521662&clcid=0x409" -Destination powerbi-desktop.msi
# Silently install PowerBI Desktop
msiexec.exe /i powerbi-desktop.msi /qn /norestart ACCEPT_EULA=1
if (!$?)
{
Write-Host -ForeGroundColor Red "Error installing Power BI Desktop. Please install latest Power BI manually."
}
cd $originalLocation.Path
$endTime= Get-Date
$totalTime = $endTime - $startTime
Write-Host "Finished running setup at " $endTime
Write-Host "Total time for setup:" $totalTime
Stop-Transcript

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

@ -1,14 +0,0 @@
<#
.SYNOPSIS
Script to invoke the LoanChargeOff data science workflow
.DESCRIPTION
This script by default uses a smaller dataset of 10,000 loans for the first time.
It creates the SQL Server user and uses it to create the database.
#>
# Download PowerBI Desktop installer
Start-BitsTransfer -Source "https://go.microsoft.com/fwlink/?LinkId=521662&clcid=0x409" -Destination powerbi-desktop.msi
# Silently install PowerBI Desktop
msiexec.exe /i powerbi-desktop.msi /qn /norestart ACCEPT_EULA=1

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

@ -1,107 +0,0 @@
<#
.SYNOPSIS
Script to invoke the LoanChargeOff data science workflow
.DESCRIPTION
This script by default uses a smaller dataset of 10,000 loans for the first time.
It creates the SQL Server user and uses it to create the database.
.WARNING
This script should only be run once through the template deployment process. It is
not meant to be run by users as it assumes database and users don't already exist.
.PARAMETER datadir
directory where raw csv data has been downloaded
.PARAMETER scriptdir
directory where scripts are checked out from github
.PARAMETER sqlUsername
User to create in SQL Server
.PARAMETER sqlPassword
Password for the SQL User
.PARAMETER dbname
Name of the database to create in SQL Server
#>
[CmdletBinding()]
Param(
[parameter(Mandatory=$true, Position=1, ParameterSetName = "LCR")]
[ValidateNotNullOrEmpty()]
[string]$datadir,
[parameter(Mandatory=$true, Position=2, ParameterSetName = "LCR")]
[ValidateNotNullOrEmpty()]
[string]$scriptdir,
[parameter(Mandatory=$true, Position=3, ParameterSetName = "LCR")]
[ValidateNotNullOrEmpty()]
[string]$sqlUsername,
[parameter(Mandatory=$true, Position=4, ParameterSetName = "LCR")]
[ValidateNotNullOrEmpty()]
[string]$sqlPassword,
[parameter(Mandatory=$false, Position=5, ParameterSetName = "LCR")]
[ValidateNotNullOrEmpty()]
[string]$dbname="LoanChargeOff"
)
# Change SQL Server to mixed mode authentication
### Check and see if SQL Service is Running , if not start it
$ServiceName = 'MSSQLSERVER'
$arrService = Get-Service -Name $ServiceName
if ($arrService.Status -ne "Running"){
Start-Service $ServiceName}
### Change Authentication From Windows Auth to Mixed Mode
Invoke-Sqlcmd -Query "EXEC xp_instance_regwrite N'HKEY_LOCAL_MACHINE', N'Software\Microsoft\MSSQLServer\MSSQLServer', N'LoginMode', REG_DWORD, 2;" -ServerInstance "LocalHost"
### Stop the SQL Service
Stop-Service -Force $ServiceName
### Start the SQL Service
Start-Service $ServiceName
### Start SQL Launch Pad and SQL Server Agent as this is Dependent on the SQL Service and is stopped with -force
Start-Service MSSQLLaunchpad
Start-Service SQLSERVERAGENT
cd $scriptdir
# create the database user
Write-Host -ForegroundColor 'Cyan' "Creating database user"
# Variables to pass to createuser.sql script
# Cannot use -v option as sqlcmd does not like special characters which maybe part of the randomly generated password.
$sqlcmdvars = @{"username" = "$sqlUsername"; "password" = "$sqlPassword"}
$old_env = @{}
foreach ($var in $sqlcmdvars.GetEnumerator()) {
# Save Environment
$old_env.Add($var.Name, [Environment]::GetEnvironmentVariable($var.Value, "User"))
[Environment]::SetEnvironmentVariable($var.Name, $var.Value)
}
try {
#sqlcmd -S $env:COMPUTERNAME -b -i .\createuser.sql
Invoke-Sqlcmd -ServerInstance $env:COMPUTERNAME -InputFile .\createuser.sql
} catch {
Write-Host -ForegroundColor 'Yellow' "Error creating database user, see error message output"
Write-Host -ForegroundColor 'Red' $Error[0].Exception
} finally {
# Restore Environment
foreach ($var in $old_env.GetEnumerator()) {
[Environment]::SetEnvironmentVariable($var.Name, $var.Value)
}
}
Write-Host -ForegroundColor 'Cyan' "Done creating database user"
# Create database if doesn't exist
$query = "IF NOT EXISTS(SELECT * FROM sys.databases WHERE NAME = '$dbname') CREATE DATABASE $dbname"
Invoke-Sqlcmd -ServerInstance $ServerName -Username $sqlUsername -Password "$sqlPassword" -Query $query -ErrorAction SilentlyContinue
if ($? -eq $false)
{
Write-Host -ForegroundColor Red "Failed to execute sql query to create database."
}
.\Loan_ChargeOff.ps1 -ServerName $env:COMPUTERNAME -DBName $dbname -sqlUsername $sqlUsername -sqlPassword "$sqlPassword" -uninterrupted y -dataPath $datadir