├── .gitignore
├── NcaaMarchMadness
├── .gitignore
├── .settings
│ ├── org.eclipse.m2e.core.prefs
│ └── org.eclipse.jdt.core.prefs
├── src
│ ├── main
│ │ ├── sql
│ │ │ ├── rebuild_db.sql
│ │ │ ├── drop_tables.sql
│ │ │ ├── drop_views.sql
│ │ │ ├── find_missing_team_names.sql
│ │ │ └── build_db.sql
│ │ ├── LOG.txt
│ │ ├── resources
│ │ │ ├── log4j.xml
│ │ │ └── network.properties
│ │ ├── data
│ │ │ ├── tourney_teams_file_2010.txt
│ │ │ ├── tourney_teams_file_2017.txt
│ │ │ ├── tourney_teams_file_2015.txt
│ │ │ ├── tourney_teams_file_2016.txt
│ │ │ ├── tourney_teams_file_2011.txt
│ │ │ ├── tourney_teams_file_2013.txt
│ │ │ ├── tourney_teams_file_2014.txt
│ │ │ └── tourney_teams_file_2012.txt
│ │ ├── java
│ │ │ └── com
│ │ │ │ └── makotojava
│ │ │ │ └── ncaabb
│ │ │ │ ├── dao
│ │ │ │ ├── TournamentAnalyticsDao.java
│ │ │ │ ├── SeasonAnalyticsDao.java
│ │ │ │ ├── TournamentResultDao.java
│ │ │ │ ├── SeasonDataDao.java
│ │ │ │ ├── TournamentAnalyticsJdbcDao.java
│ │ │ │ └── TournamentResultJdbcDao.java
│ │ │ │ ├── sqlgenerator
│ │ │ │ ├── Strategy.java
│ │ │ │ ├── TournamentParticipant.java
│ │ │ │ ├── AbstractStrategy.java
│ │ │ │ ├── ScoringOffense.java
│ │ │ │ ├── ScoringDefense.java
│ │ │ │ ├── StealsPerGame.java
│ │ │ │ ├── WonLostPercentageStrategy.java
│ │ │ │ ├── TurnoversPerGame.java
│ │ │ │ ├── BlockedShotsPerGame.java
│ │ │ │ ├── ThreePointFieldGoalsPerGame.java
│ │ │ │ ├── AssistsPerGame.java
│ │ │ │ ├── AssistTurnoverRatio.java
│ │ │ │ ├── PersonalFoulsPerGame.java
│ │ │ │ ├── ScoringMargin.java
│ │ │ │ ├── FreeThrowPercentage.java
│ │ │ │ ├── FieldGoalPercentage.java
│ │ │ │ ├── ThreePointPercentage.java
│ │ │ │ ├── FieldGoalPercentageDefense.java
│ │ │ │ ├── ThreePointPercentageDefense.java
│ │ │ │ ├── TurnoverMargin.java
│ │ │ │ ├── ReboundMargin.java
│ │ │ │ ├── TournamentResult.java
│ │ │ │ └── TournamentParticipantSqlGenerator.java
│ │ │ │ ├── model
│ │ │ │ ├── TournamentAnalytics.java
│ │ │ │ └── TournamentResult.java
│ │ │ │ ├── simulation
│ │ │ │ └── NetworkRunner.java
│ │ │ │ ├── generation
│ │ │ │ └── Networks.java
│ │ │ │ ├── util
│ │ │ │ └── StatsUtils.java
│ │ │ │ └── springconfig
│ │ │ │ └── ApplicationConfig.java
│ │ └── script
│ │ │ ├── run-tournament-simulator.sh
│ │ │ ├── run-data-creator.sh
│ │ │ ├── run-sql-generator.sh
│ │ │ ├── run-tournament_participant-sql-generator.sh
│ │ │ └── run-mlp-trainer.sh
│ └── test
│ │ └── java
│ │ └── com
│ │ └── makotojava
│ │ └── ncaabb
│ │ ├── generation
│ │ └── MlpNetworkTrainerTest.java
│ │ └── dao
│ │ ├── TournamentResultJdbcDaoTest.java
│ │ ├── SeasonAnalyticsJdbcDaoTest.java
│ │ └── TournamentAnalyticsJdbcDaoTest.java
├── .project
└── .classpath
├── perishable-network
├── config
│ └── default.json
├── .eslintignore
├── header.txt
├── index.js
├── .npmignore
├── .gitignore
├── features
│ └── support
│ │ └── index.js
├── jsdoc.json
├── permissions.acl
├── .eslintrc.yml
├── package.json
├── README.md
├── models
│ └── perishable.cto
└── networkimage.svg
├── iot-perishable-network
├── config
│ └── default.json
├── .eslintignore
├── header.txt
├── index.js
├── .npmignore
├── .gitignore
├── features
│ └── support
│ │ └── index.js
├── jsdoc.json
├── permissions.acl
├── .eslintrc.yml
├── package.json
├── README.md
├── models
│ └── perishable.cto
└── networkimage.svg
├── iot-perishable-network-advanced
├── config
│ └── default.json
├── .eslintignore
├── header.txt
├── index.js
├── .npmignore
├── .gitignore
├── features
│ ├── support
│ │ └── index.js
│ ├── grower.feature
│ └── shipper.feature
├── jsdoc.json
├── .eslintrc.yml
├── package.json
├── networkimage.svg
└── permissions.acl
├── README.md
└── kubernetes
├── Dockerfile
├── test-k8sdemo.sh
└── k8sdemo.js
/.gitignore:
--------------------------------------------------------------------------------
1 | /.metadata/
2 | .DS_Store
3 |
--------------------------------------------------------------------------------
/NcaaMarchMadness/.gitignore:
--------------------------------------------------------------------------------
1 | /target/
2 | /attic/
3 |
--------------------------------------------------------------------------------
/perishable-network/config/default.json:
--------------------------------------------------------------------------------
1 | {
2 |
3 | "config":""
4 | }
5 |
--------------------------------------------------------------------------------
/iot-perishable-network/config/default.json:
--------------------------------------------------------------------------------
1 | {
2 |
3 | "config":""
4 | }
5 |
--------------------------------------------------------------------------------
/iot-perishable-network-advanced/config/default.json:
--------------------------------------------------------------------------------
1 | {
2 |
3 | "config":""
4 | }
5 |
--------------------------------------------------------------------------------
/iot-perishable-network/.eslintignore:
--------------------------------------------------------------------------------
1 | coverage
2 | dist
3 | go
4 | lib
5 | node_modules
6 | out
7 |
--------------------------------------------------------------------------------
/perishable-network/.eslintignore:
--------------------------------------------------------------------------------
1 | coverage
2 | dist
3 | go
4 | lib
5 | node_modules
6 | out
7 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # developerWorks
2 | Code for tutorials and articles I have written for IBM developerWorks
3 |
--------------------------------------------------------------------------------
/iot-perishable-network-advanced/.eslintignore:
--------------------------------------------------------------------------------
1 | coverage
2 | dist
3 | go
4 | lib
5 | node_modules
6 | out
7 |
--------------------------------------------------------------------------------
/kubernetes/Dockerfile:
--------------------------------------------------------------------------------
1 | FROM node:6.11.4
2 | EXPOSE 8080
3 | COPY k8sdemo.js .
4 | CMD node k8sdemo.js
5 |
--------------------------------------------------------------------------------
/NcaaMarchMadness/.settings/org.eclipse.m2e.core.prefs:
--------------------------------------------------------------------------------
1 | activeProfiles=
2 | eclipse.preferences.version=1
3 | resolveWorkspaceProjects=true
4 | version=1
5 |
--------------------------------------------------------------------------------
/NcaaMarchMadness/.settings/org.eclipse.jdt.core.prefs:
--------------------------------------------------------------------------------
1 | eclipse.preferences.version=1
2 | org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
3 | org.eclipse.jdt.core.compiler.compliance=1.8
4 | org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
5 | org.eclipse.jdt.core.compiler.source=1.8
6 |
--------------------------------------------------------------------------------
/kubernetes/test-k8sdemo.sh:
--------------------------------------------------------------------------------
1 | #! /bin/bash
2 |
3 | # Default port to 8001 unless specified
4 | PORT="${1:-8001}"
5 |
6 | # Set POD_NAME
7 | POD_NAME=$(kubectl get pods -o go-template --template '{{range .items}}{{.metadata.name}}{{"\n"}}{{end}}')
8 |
9 | curl http://localhost:$PORT/api/v1/proxy/namespaces/default/pods/$POD_NAME/
10 |
--------------------------------------------------------------------------------
/kubernetes/k8sdemo.js:
--------------------------------------------------------------------------------
1 | var http = require('http');
2 |
3 | var handleRequest = function(request, response) {
4 | console.log('Received request for URL: ' + request.url);
5 | response.writeHead(200);
6 | response.write('****************************\n');
7 | response.write('* Greetings from the DEMO! *\n');
8 | response.end( '****************************\n');
9 | };
10 | var www = http.createServer(handleRequest);
11 | www.listen(8080);
12 |
--------------------------------------------------------------------------------
/perishable-network/header.txt:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed under the Apache License, Version 2.0 (the "License");
3 | * you may not use this file except in compliance with the License.
4 | * You may obtain a copy of the License at
5 | *
6 | * http://www.apache.org/licenses/LICENSE-2.0
7 | *
8 | * Unless required by applicable law or agreed to in writing, software
9 | * distributed under the License is distributed on an "AS IS" BASIS,
10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11 | * See the License for the specific language governing permissions and
12 | * limitations under the License.
13 | */
14 |
--------------------------------------------------------------------------------
/perishable-network/index.js:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed under the Apache License, Version 2.0 (the "License");
3 | * you may not use this file except in compliance with the License.
4 | * You may obtain a copy of the License at
5 | *
6 | * http://www.apache.org/licenses/LICENSE-2.0
7 | *
8 | * Unless required by applicable law or agreed to in writing, software
9 | * distributed under the License is distributed on an "AS IS" BASIS,
10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11 | * See the License for the specific language governing permissions and
12 | * limitations under the License.
13 | */
14 |
--------------------------------------------------------------------------------
/iot-perishable-network/header.txt:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed under the Apache License, Version 2.0 (the "License");
3 | * you may not use this file except in compliance with the License.
4 | * You may obtain a copy of the License at
5 | *
6 | * http://www.apache.org/licenses/LICENSE-2.0
7 | *
8 | * Unless required by applicable law or agreed to in writing, software
9 | * distributed under the License is distributed on an "AS IS" BASIS,
10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11 | * See the License for the specific language governing permissions and
12 | * limitations under the License.
13 | */
14 |
--------------------------------------------------------------------------------
/iot-perishable-network/index.js:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed under the Apache License, Version 2.0 (the "License");
3 | * you may not use this file except in compliance with the License.
4 | * You may obtain a copy of the License at
5 | *
6 | * http://www.apache.org/licenses/LICENSE-2.0
7 | *
8 | * Unless required by applicable law or agreed to in writing, software
9 | * distributed under the License is distributed on an "AS IS" BASIS,
10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11 | * See the License for the specific language governing permissions and
12 | * limitations under the License.
13 | */
14 |
--------------------------------------------------------------------------------
/iot-perishable-network-advanced/header.txt:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed under the Apache License, Version 2.0 (the "License");
3 | * you may not use this file except in compliance with the License.
4 | * You may obtain a copy of the License at
5 | *
6 | * http://www.apache.org/licenses/LICENSE-2.0
7 | *
8 | * Unless required by applicable law or agreed to in writing, software
9 | * distributed under the License is distributed on an "AS IS" BASIS,
10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11 | * See the License for the specific language governing permissions and
12 | * limitations under the License.
13 | */
14 |
--------------------------------------------------------------------------------
/iot-perishable-network-advanced/index.js:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed under the Apache License, Version 2.0 (the "License");
3 | * you may not use this file except in compliance with the License.
4 | * You may obtain a copy of the License at
5 | *
6 | * http://www.apache.org/licenses/LICENSE-2.0
7 | *
8 | * Unless required by applicable law or agreed to in writing, software
9 | * distributed under the License is distributed on an "AS IS" BASIS,
10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11 | * See the License for the specific language governing permissions and
12 | * limitations under the License.
13 | */
14 |
--------------------------------------------------------------------------------
/NcaaMarchMadness/src/main/sql/rebuild_db.sql:
--------------------------------------------------------------------------------
1 | -- You should probably run this inside of a TX block
2 | \set ROOT_DIR ''/Users/sperry/home/development/projects/developerWorks/NcaaMarchMadness/src/main''
3 | \set SQL_ROOT_DIR :ROOT_DIR/sql
4 | \set DATA_ROOT_DIR :ROOT_DIR/data
5 | \set LOAD_SCRIPT_ROOT_DIR ''/Users/sperry/l/MarchMadness/data''
6 | \o :ROOT_DIR/LOG.txt
7 |
8 | \echo 'REBUILDING DB...'
9 | \qecho 'REBUILDING DB...'
10 |
11 | \echo 'DROPPING ALL VIEWS...'
12 | \qecho 'DROPPING ALL VIEWS...'
13 | \i :SQL_ROOT_DIR/drop_views.sql
14 |
15 | \echo 'DROPPING ALL TABLES...'
16 | \qecho 'DROPPING ALL TABLES...'
17 | \i :SQL_ROOT_DIR/drop_tables.sql
18 |
19 | -- Run the main build script
20 | \i :SQL_ROOT_DIR/build_db.sql
21 |
22 | \o
--------------------------------------------------------------------------------
/NcaaMarchMadness/src/main/LOG.txt:
--------------------------------------------------------------------------------
1 | REBUILDING DB...
2 | DROPPING ALL VIEWS...
3 | DROP VIEW
4 | DROP VIEW
5 | DROP VIEW
6 | DROP VIEW
7 | DROP VIEW
8 | DROP VIEW
9 | DROP VIEW
10 | DROP VIEW
11 | DROP VIEW
12 | DROP VIEW
13 | DROP VIEW
14 | DROP VIEW
15 | DROP VIEW
16 | DROP VIEW
17 | DROP VIEW
18 | DROP VIEW
19 | DROP VIEW
20 | DROP VIEW
21 | DROP VIEW
22 | DROP VIEW
23 | DROP VIEW
24 | DROP VIEW
25 | DROP VIEW
26 | DROPPING ALL TABLES...
27 | DROP TABLE
28 | DROP TABLE
29 | DROP TABLE
30 | DROP TABLE
31 | DROP TABLE
32 | DROP TABLE
33 | DROP TABLE
34 | DROP TABLE
35 | DROP TABLE
36 | DROP TABLE
37 | DROP TABLE
38 | DROP TABLE
39 | DROP TABLE
40 | DROP TABLE
41 | DROP TABLE
42 | DROP TABLE
43 | DROP TABLE
44 | DROP TABLE
45 | DROP TABLE
46 | DROP TABLE
47 |
--------------------------------------------------------------------------------
/NcaaMarchMadness/.project:
--------------------------------------------------------------------------------
1 |
2 |
3 | MarchMadness
4 | NO_M2ECLIPSE_SUPPORT: Project files created with the maven-eclipse-plugin are not supported in M2Eclipse.
5 |
6 |
7 |
8 |
9 | org.eclipse.jdt.core.javabuilder
10 |
11 |
12 |
13 |
14 | org.eclipse.m2e.core.maven2Builder
15 |
16 |
17 |
18 |
19 |
20 | org.eclipse.m2e.core.maven2Nature
21 | org.eclipse.jdt.core.javanature
22 |
23 |
24 |
--------------------------------------------------------------------------------
/NcaaMarchMadness/src/main/resources/log4j.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
5 |
6 |
7 |
8 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
--------------------------------------------------------------------------------
/iot-perishable-network/.npmignore:
--------------------------------------------------------------------------------
1 | # Logs
2 | logs
3 | *.log
4 | npm-debug.log*
5 |
6 | # Runtime data
7 | pids
8 | *.pid
9 | *.seed
10 |
11 | # Directory for instrumented libs generated by jscoverage/JSCover
12 | lib-cov
13 |
14 | # Coverage directory used by tools like istanbul
15 | coverage
16 |
17 | # nyc test coverage
18 | .nyc_output
19 |
20 | # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
21 | .grunt
22 |
23 | # node-waf configuration
24 | .lock-wscript
25 |
26 | # Compiled binary addons (http://nodejs.org/api/addons.html)
27 | build/Release
28 |
29 | # Dependency directories
30 | node_modules
31 | jspm_packages
32 |
33 | # Optional npm cache directory
34 | .npm
35 |
36 | # Optional REPL history
37 | .node_repl_history
38 |
39 | # JSDoc
40 | out
41 |
42 | # Mac files.
43 | **/.DS_Store
44 |
45 | *.swp
46 |
47 | # Build generated files should be ignored by git, but not by npm.
48 | # dist
49 |
--------------------------------------------------------------------------------
/perishable-network/.npmignore:
--------------------------------------------------------------------------------
1 | # Logs
2 | logs
3 | *.log
4 | npm-debug.log*
5 |
6 | # Runtime data
7 | pids
8 | *.pid
9 | *.seed
10 |
11 | # Directory for instrumented libs generated by jscoverage/JSCover
12 | lib-cov
13 |
14 | # Coverage directory used by tools like istanbul
15 | coverage
16 |
17 | # nyc test coverage
18 | .nyc_output
19 |
20 | # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
21 | .grunt
22 |
23 | # node-waf configuration
24 | .lock-wscript
25 |
26 | # Compiled binary addons (http://nodejs.org/api/addons.html)
27 | build/Release
28 |
29 | # Dependency directories
30 | node_modules
31 | jspm_packages
32 |
33 | # Optional npm cache directory
34 | .npm
35 |
36 | # Optional REPL history
37 | .node_repl_history
38 |
39 | # JSDoc
40 | out
41 |
42 | # Mac files.
43 | **/.DS_Store
44 |
45 | *.swp
46 |
47 | # Build generated files should be ignored by git, but not by npm.
48 | # dist
49 |
--------------------------------------------------------------------------------
/iot-perishable-network-advanced/.npmignore:
--------------------------------------------------------------------------------
1 | # Logs
2 | logs
3 | *.log
4 | npm-debug.log*
5 |
6 | # Runtime data
7 | pids
8 | *.pid
9 | *.seed
10 |
11 | # Directory for instrumented libs generated by jscoverage/JSCover
12 | lib-cov
13 |
14 | # Coverage directory used by tools like istanbul
15 | coverage
16 |
17 | # nyc test coverage
18 | .nyc_output
19 |
20 | # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
21 | .grunt
22 |
23 | # node-waf configuration
24 | .lock-wscript
25 |
26 | # Compiled binary addons (http://nodejs.org/api/addons.html)
27 | build/Release
28 |
29 | # Dependency directories
30 | node_modules
31 | jspm_packages
32 |
33 | # Optional npm cache directory
34 | .npm
35 |
36 | # Optional REPL history
37 | .node_repl_history
38 |
39 | # JSDoc
40 | out
41 |
42 | # Mac files.
43 | **/.DS_Store
44 |
45 | *.swp
46 |
47 | # Build generated files should be ignored by git, but not by npm.
48 | # dist
49 |
--------------------------------------------------------------------------------
/perishable-network/.gitignore:
--------------------------------------------------------------------------------
1 | # Logs
2 | logs
3 | *.log
4 | npm-debug.log*
5 |
6 | # Runtime data
7 | pids
8 | *.pid
9 | *.seed
10 |
11 | # Directory for instrumented libs generated by jscoverage/JSCover
12 | lib-cov
13 |
14 | # Coverage directory used by tools like istanbul
15 | coverage
16 |
17 | # nyc test coverage
18 | .nyc_output
19 |
20 | # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
21 | .grunt
22 |
23 | # node-waf configuration
24 | .lock-wscript
25 |
26 | # Compiled binary addons (http://nodejs.org/api/addons.html)
27 | build/Release
28 |
29 | # Dependency directories
30 | node_modules
31 | jspm_packages
32 |
33 | # Optional npm cache directory
34 | .npm
35 |
36 | # Optional REPL history
37 | .node_repl_history
38 |
39 | # JSDoc
40 | out
41 |
42 | # Mac files.
43 | **/.DS_Store
44 |
45 | *.swp
46 |
47 | # Build generated files should be ignored by git, but not by npm.
48 | dist
49 |
50 | node_modules
51 |
--------------------------------------------------------------------------------
/NcaaMarchMadness/src/main/sql/drop_tables.sql:
--------------------------------------------------------------------------------
1 | DROP TABLE IF EXISTS tournament_participant;
2 | DROP TABLE IF EXISTS tournament_result;
3 | DROP TABLE IF EXISTS won_lost_percentage;
4 | DROP TABLE IF EXISTS scoring_offense;
5 | DROP TABLE IF EXISTS scoring_defense;
6 | DROP TABLE IF EXISTS scoring_margin;
7 | DROP TABLE IF EXISTS field_goal_percentage;
8 | DROP TABLE IF EXISTS field_goal_percentage_defense;
9 | DROP TABLE IF EXISTS three_point_field_goals_per_game;
10 | DROP TABLE IF EXISTS three_point_percentage;
11 | DROP TABLE IF EXISTS three_point_percentage_defense;
12 | DROP TABLE IF EXISTS free_throw_percentage;
13 | DROP TABLE IF EXISTS rebound_margin;
14 | DROP TABLE IF EXISTS assists_per_game;
15 | DROP TABLE IF EXISTS assist_turnover_ratio;
16 | DROP TABLE IF EXISTS blocked_shots_per_game;
17 | DROP TABLE IF EXISTS steals_per_game;
18 | DROP TABLE IF EXISTS turnovers_per_game;
19 | DROP TABLE IF EXISTS turnover_margin;
20 | DROP TABLE IF EXISTS personal_fouls_per_game;
--------------------------------------------------------------------------------
/iot-perishable-network/.gitignore:
--------------------------------------------------------------------------------
1 | # Logs
2 | logs
3 | *.log
4 | npm-debug.log*
5 |
6 | # Runtime data
7 | pids
8 | *.pid
9 | *.seed
10 |
11 | # Directory for instrumented libs generated by jscoverage/JSCover
12 | lib-cov
13 |
14 | # Coverage directory used by tools like istanbul
15 | coverage
16 |
17 | # nyc test coverage
18 | .nyc_output
19 |
20 | # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
21 | .grunt
22 |
23 | # node-waf configuration
24 | .lock-wscript
25 |
26 | # Compiled binary addons (http://nodejs.org/api/addons.html)
27 | build/Release
28 |
29 | # Dependency directories
30 | node_modules
31 | jspm_packages
32 |
33 | # Optional npm cache directory
34 | .npm
35 |
36 | # Optional REPL history
37 | .node_repl_history
38 |
39 | # JSDoc
40 | out
41 |
42 | # Mac files.
43 | **/.DS_Store
44 |
45 | *.swp
46 |
47 | # Build generated files should be ignored by git, but not by npm.
48 | dist
49 |
50 | node_modules
51 |
52 | *.card
--------------------------------------------------------------------------------
/iot-perishable-network-advanced/.gitignore:
--------------------------------------------------------------------------------
1 | # Logs
2 | logs
3 | *.log
4 | npm-debug.log*
5 |
6 | # Runtime data
7 | pids
8 | *.pid
9 | *.seed
10 |
11 | # Directory for instrumented libs generated by jscoverage/JSCover
12 | lib-cov
13 |
14 | # Coverage directory used by tools like istanbul
15 | coverage
16 |
17 | # nyc test coverage
18 | .nyc_output
19 |
20 | # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
21 | .grunt
22 |
23 | # node-waf configuration
24 | .lock-wscript
25 |
26 | # Compiled binary addons (http://nodejs.org/api/addons.html)
27 | build/Release
28 |
29 | # Dependency directories
30 | node_modules
31 | jspm_packages
32 |
33 | # Optional npm cache directory
34 | .npm
35 |
36 | # Optional REPL history
37 | .node_repl_history
38 |
39 | # JSDoc
40 | out
41 |
42 | # Mac files.
43 | **/.DS_Store
44 |
45 | *.swp
46 |
47 | # Build generated files should be ignored by git, but not by npm.
48 | dist
49 |
50 | node_modules
51 |
52 | *.card
--------------------------------------------------------------------------------
/iot-perishable-network/features/support/index.js:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed under the Apache License, Version 2.0 (the "License");
3 | * you may not use this file except in compliance with the License.
4 | * You may obtain a copy of the License at
5 | *
6 | * http://www.apache.org/licenses/LICENSE-2.0
7 | *
8 | * Unless required by applicable law or agreed to in writing, software
9 | * distributed under the License is distributed on an "AS IS" BASIS,
10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11 | * See the License for the specific language governing permissions and
12 | * limitations under the License.
13 | */
14 |
15 | 'use strict';
16 |
17 | const composerSteps = require('composer-cucumber-steps');
18 | const cucumber = require('cucumber');
19 |
20 | module.exports = function () {
21 | composerSteps.call(this);
22 | };
23 |
24 | if (cucumber.defineSupportCode) {
25 | cucumber.defineSupportCode((context) => {
26 | module.exports.call(context);
27 | });
28 | }
29 |
--------------------------------------------------------------------------------
/perishable-network/features/support/index.js:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed under the Apache License, Version 2.0 (the "License");
3 | * you may not use this file except in compliance with the License.
4 | * You may obtain a copy of the License at
5 | *
6 | * http://www.apache.org/licenses/LICENSE-2.0
7 | *
8 | * Unless required by applicable law or agreed to in writing, software
9 | * distributed under the License is distributed on an "AS IS" BASIS,
10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11 | * See the License for the specific language governing permissions and
12 | * limitations under the License.
13 | */
14 |
15 | 'use strict';
16 |
17 | const composerSteps = require('composer-cucumber-steps');
18 | const cucumber = require('cucumber');
19 |
20 | module.exports = function () {
21 | composerSteps.call(this);
22 | };
23 |
24 | if (cucumber.defineSupportCode) {
25 | cucumber.defineSupportCode((context) => {
26 | module.exports.call(context);
27 | });
28 | }
29 |
--------------------------------------------------------------------------------
/iot-perishable-network-advanced/features/support/index.js:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed under the Apache License, Version 2.0 (the "License");
3 | * you may not use this file except in compliance with the License.
4 | * You may obtain a copy of the License at
5 | *
6 | * http://www.apache.org/licenses/LICENSE-2.0
7 | *
8 | * Unless required by applicable law or agreed to in writing, software
9 | * distributed under the License is distributed on an "AS IS" BASIS,
10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11 | * See the License for the specific language governing permissions and
12 | * limitations under the License.
13 | */
14 |
15 | 'use strict';
16 |
17 | const composerSteps = require('composer-cucumber-steps');
18 | const cucumber = require('cucumber');
19 |
20 | module.exports = function () {
21 | composerSteps.call(this);
22 | };
23 |
24 | if (cucumber.defineSupportCode) {
25 | cucumber.defineSupportCode((context) => {
26 | module.exports.call(context);
27 | });
28 | }
29 |
--------------------------------------------------------------------------------
/perishable-network/jsdoc.json:
--------------------------------------------------------------------------------
1 | {
2 | "tags": {
3 | "allowUnknownTags": true,
4 | "dictionaries": ["jsdoc","closure"]
5 | },
6 | "source": {
7 | "include": [
8 | "./lib"
9 | ],
10 | "includePattern": ".+\\.js(doc|x)?$"
11 | },
12 | "plugins": ["plugins/markdown"],
13 | "templates": {
14 | "logoFile": "",
15 | "cleverLinks": false,
16 | "monospaceLinks": false,
17 | "dateFormat": "ddd MMM Do YYYY",
18 | "outputSourceFiles": true,
19 | "outputSourcePath": true,
20 | "systemName": "Perishable Goods Network",
21 | "footer": "",
22 | "copyright": "Released under the Apache License v2.0",
23 | "navType": "vertical",
24 | "theme": "spacelab",
25 | "linenums": true,
26 | "collapseSymbols": false,
27 | "inverseNav": true,
28 | "protocol": "html://",
29 | "methodHeadingReturns": false
30 | },
31 | "markdown": {
32 | "parser": "gfm",
33 | "hardwrap": true
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/iot-perishable-network/jsdoc.json:
--------------------------------------------------------------------------------
1 | {
2 | "tags": {
3 | "allowUnknownTags": true,
4 | "dictionaries": ["jsdoc","closure"]
5 | },
6 | "source": {
7 | "include": [
8 | "./lib"
9 | ],
10 | "includePattern": ".+\\.js(doc|x)?$"
11 | },
12 | "plugins": ["plugins/markdown"],
13 | "templates": {
14 | "logoFile": "",
15 | "cleverLinks": false,
16 | "monospaceLinks": false,
17 | "dateFormat": "ddd MMM Do YYYY",
18 | "outputSourceFiles": true,
19 | "outputSourcePath": true,
20 | "systemName": "IoT Perishable Goods Network",
21 | "footer": "",
22 | "copyright": "Released under the Apache License v2.0",
23 | "navType": "vertical",
24 | "theme": "spacelab",
25 | "linenums": true,
26 | "collapseSymbols": false,
27 | "inverseNav": true,
28 | "protocol": "html://",
29 | "methodHeadingReturns": false
30 | },
31 | "markdown": {
32 | "parser": "gfm",
33 | "hardwrap": true
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/NcaaMarchMadness/src/main/sql/drop_views.sql:
--------------------------------------------------------------------------------
1 | --
2 | -- Drop views used for the model
3 | --
4 | DROP VIEW v_tourament_analytics;
5 | DROP VIEW v_season_analytics;
6 | DROP VIEW v_season_data;
7 | DROP VIEW v_errors;
8 | DROP VIEW v_defense;
9 | DROP VIEW v_offense;
10 | --
11 | -- Drop all views for the statistical categories for
12 | -- tournament participants.
13 | --
14 | DROP VIEW v_won_lost_percentage;
15 | DROP VIEW v_scoring_offense;
16 | DROP VIEW v_scoring_defense;
17 | DROP VIEW v_scoring_margin;
18 | DROP VIEW v_field_goal_percentage;
19 | DROP VIEW v_field_goal_percentage_defense;
20 | DROP VIEW v_three_point_field_goals_per_game;
21 | DROP VIEW v_three_point_percentage;
22 | DROP VIEW v_three_point_percentage_defense;
23 | DROP VIEW v_free_throw_percentage;
24 | DROP VIEW v_rebound_margin;
25 | DROP VIEW v_assists_per_game;
26 | DROP VIEW v_assist_turnover_ratio;
27 | DROP VIEW v_blocked_shots_per_game;
28 | DROP VIEW v_steals_per_game;
29 | DROP VIEW v_turnovers_per_game;
30 | DROP VIEW v_turnover_margin;
31 | DROP VIEW v_personal_fouls_per_game;
32 |
33 |
--------------------------------------------------------------------------------
/iot-perishable-network-advanced/jsdoc.json:
--------------------------------------------------------------------------------
1 | {
2 | "tags": {
3 | "allowUnknownTags": true,
4 | "dictionaries": ["jsdoc","closure"]
5 | },
6 | "source": {
7 | "include": [
8 | "./lib"
9 | ],
10 | "includePattern": ".+\\.js(doc|x)?$"
11 | },
12 | "plugins": ["plugins/markdown"],
13 | "templates": {
14 | "logoFile": "",
15 | "cleverLinks": false,
16 | "monospaceLinks": false,
17 | "dateFormat": "ddd MMM Do YYYY",
18 | "outputSourceFiles": true,
19 | "outputSourcePath": true,
20 | "systemName": "IoT Perishable Goods Network",
21 | "footer": "",
22 | "copyright": "Released under the Apache License v2.0",
23 | "navType": "vertical",
24 | "theme": "spacelab",
25 | "linenums": true,
26 | "collapseSymbols": false,
27 | "inverseNav": true,
28 | "protocol": "html://",
29 | "methodHeadingReturns": false
30 | },
31 | "markdown": {
32 | "parser": "gfm",
33 | "hardwrap": true
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/perishable-network/permissions.acl:
--------------------------------------------------------------------------------
1 | /**
2 | * Sample access control list.
3 | */
4 | rule Default {
5 | description: "Allow all participants access to all resources"
6 | participant: "ANY"
7 | operation: ALL
8 | resource: "org.acme.shipping.perishable.*"
9 | action: ALLOW
10 | }
11 |
12 | rule SystemACL {
13 | description: "System ACL to permit all access"
14 | participant: "org.hyperledger.composer.system.Participant"
15 | operation: ALL
16 | resource: "org.hyperledger.composer.system.**"
17 | action: ALLOW
18 | }
19 |
20 | rule NetworkAdminUser {
21 | description: "Grant business network administrators full access to user resources"
22 | participant: "org.hyperledger.composer.system.NetworkAdmin"
23 | operation: ALL
24 | resource: "**"
25 | action: ALLOW
26 | }
27 |
28 | rule NetworkAdminSystem {
29 | description: "Grant business network administrators full access to system resources"
30 | participant: "org.hyperledger.composer.system.NetworkAdmin"
31 | operation: ALL
32 | resource: "org.hyperledger.composer.system.**"
33 | action: ALLOW
34 | }
--------------------------------------------------------------------------------
/iot-perishable-network/permissions.acl:
--------------------------------------------------------------------------------
1 | /**
2 | * Sample access control list.
3 | */
4 | rule Default {
5 | description: "Allow all participants access to all resources"
6 | participant: "ANY"
7 | operation: ALL
8 | resource: "org.acme.shipping.perishable.*"
9 | action: ALLOW
10 | }
11 |
12 | rule SystemACL {
13 | description: "System ACL to permit all access"
14 | participant: "org.hyperledger.composer.system.Participant"
15 | operation: ALL
16 | resource: "org.hyperledger.composer.system.**"
17 | action: ALLOW
18 | }
19 |
20 | rule NetworkAdminUser {
21 | description: "Grant business network administrators full access to user resources"
22 | participant: "org.hyperledger.composer.system.NetworkAdmin"
23 | operation: ALL
24 | resource: "**"
25 | action: ALLOW
26 | }
27 |
28 | rule NetworkAdminSystem {
29 | description: "Grant business network administrators full access to system resources"
30 | participant: "org.hyperledger.composer.system.NetworkAdmin"
31 | operation: ALL
32 | resource: "org.hyperledger.composer.system.**"
33 | action: ALLOW
34 | }
--------------------------------------------------------------------------------
/NcaaMarchMadness/src/main/data/tourney_teams_file_2010.txt:
--------------------------------------------------------------------------------
1 | NCAA Men's Basketball
2 | DivisionITournament Participants
3 | Through Games 1/1/2010
4 |
5 | Ark-Pine Bluff
6 | BYU
7 | Baylor
8 | Butler
9 | California
10 | Clemson
11 | Cornell
12 | Duke
13 | ETSU
14 | Florida
15 | Florida St
16 | Georgetown
17 | Georgia Tech
18 | Gonzaga
19 | Houston
20 | Kansas
21 | Kansas St
22 | Kentucky
23 | Lehigh
24 | Louisville
25 | Marquette
26 | Maryland
27 | Michigan St
28 | Minnesota
29 | Missouri
30 | Montana
31 | Morgan St
32 | Murray St
33 | New Mexico
34 | New Mexico St
35 | North Texas
36 | Notre Dame
37 | Oakland
38 | Ohio
39 | Ohio St
40 | Oklahoma St
41 | Old Dominion
42 | Pittsburgh
43 | Purdue
44 | Richmond
45 | Robert Morris
46 | Saint Marys CA
47 | Sam Houston St
48 | San Diego St
49 | Siena
50 | Syracuse
51 | Temple
52 | Tennessee
53 | Texas
54 | Texas AM
55 | UC Santa Barbara
56 | UNI
57 | UNLV
58 | UTEP
59 | Utah St
60 | Vanderbilt
61 | Vermont
62 | Villanova
63 | Wake Forest
64 | Washington
65 | West Virginia
66 | Winthrop
67 | Wisconsin
68 | Wofford
69 | Xavier
70 |
--------------------------------------------------------------------------------
/NcaaMarchMadness/src/main/data/tourney_teams_file_2017.txt:
--------------------------------------------------------------------------------
1 | NCAA Men's Basketball
2 | DivisionITournament Participants
3 | Through Games 1/1/2017
4 |
5 | Arizona
6 | Arkansas
7 | Baylor
8 | Bucknell
9 | Butler
10 | Cincinnati
11 | Creighton
12 | Dayton
13 | Duke
14 | ETSU
15 | FGCU
16 | Florida
17 | Florida St
18 | Gonzaga
19 | Iona
20 | Iowa St
21 | Jacksonville St
22 | Kansas St
23 | Kansas
24 | Kent St
25 | Kentucky
26 | Louisville
27 | Marquette
28 | Maryland
29 | Miami FL
30 | Michigan
31 | Michigan St
32 | Middle Tenn
33 | Minnesota
34 | Mt St Marys
35 | NC Central
36 | Nevada
37 | New Mexico St
38 | New Orleans
39 | North Carolina
40 | North Dakota
41 | Northern Ky
42 | Northwestern
43 | Notre Dame
44 | Oklahoma St
45 | Oregon
46 | Princeton
47 | Providence
48 | Purdue
49 | Rhode Island
50 | SMU
51 | Seton Hall
52 | South Carolina
53 | South Dakota St
54 | Saint Marys CA
55 | Texas Southern
56 | Troy
57 | UC Davis
58 | UCLA
59 | UNCW
60 | Southern California
61 | VCU
62 | Vanderbilt
63 | Vermont
64 | Villanova
65 | Virginia
66 | Virginia Tech
67 | Wake Forest
68 | West Virginia
69 | Wichita St
70 | Winthrop
71 | Wisconsin
72 | Xavier
73 |
--------------------------------------------------------------------------------
/NcaaMarchMadness/src/main/data/tourney_teams_file_2015.txt:
--------------------------------------------------------------------------------
1 | NCAA Men's Basketball
2 | DivisionITournament Participants
3 | Through Games 1/1/2015
4 |
5 | Albany NY
6 | Arizona
7 | Arkansas
8 | BYU
9 | Baylor
10 | Belmont
11 | Boise St
12 | Buffalo
13 | Butler
14 | Cincinnati
15 | Coastal Caro
16 | Davidson
17 | Dayton
18 | Duke
19 | Eastern Wash
20 | Georgetown
21 | Georgia
22 | Georgia St
23 | Gonzaga
24 | Hampton
25 | Harvard
26 | Indiana
27 | Iowa
28 | Iowa St
29 | Kansas
30 | Kentucky
31 | LSU
32 | Lafayette
33 | Louisville
34 | Manhattan
35 | Maryland
36 | Michigan St
37 | NC State
38 | New Mexico St
39 | North Carolina
40 | North Dakota St
41 | North Florida
42 | Northeastern
43 | Notre Dame
44 | Ohio St
45 | Oklahoma
46 | Oklahoma St
47 | Ole Miss
48 | Oregon
49 | Providence
50 | Purdue
51 | Robert Morris
52 | SFA
53 | SMU
54 | San Diego St
55 | St Johns NY
56 | Texas
57 | Texas Southern
58 | UAB
59 | UC Irvine
60 | UCLA
61 | UNI
62 | Utah
63 | VCU
64 | Valparaiso
65 | Villanova
66 | Virginia
67 | West Virginia
68 | Wichita St
69 | Wisconsin
70 | Wofford
71 | Wyoming
72 | Xavier
73 |
--------------------------------------------------------------------------------
/perishable-network/.eslintrc.yml:
--------------------------------------------------------------------------------
1 | env:
2 | es6: false
3 | node: true
4 | mocha: true
5 | extends: 'eslint:recommended'
6 | parserOptions:
7 | ecmaVersion: 2015
8 | sourceType:
9 | - script
10 | rules:
11 | indent:
12 | - error
13 | - 4
14 | linebreak-style:
15 | - error
16 | - unix
17 | quotes:
18 | - error
19 | - single
20 | semi:
21 | - error
22 | - always
23 | no-unused-vars:
24 | - error
25 | - args: none
26 | no-console: off
27 | curly: error
28 | eqeqeq: error
29 | no-throw-literal: error
30 | strict: error
31 | dot-notation: error
32 | no-tabs: error
33 | no-trailing-spaces: error
34 | no-use-before-define: error
35 | no-useless-call: error
36 | no-with: error
37 | operator-linebreak: error
38 | require-jsdoc:
39 | - error
40 | - require:
41 | ClassDeclaration: true
42 | MethodDefinition: true
43 | FunctionDeclaration: true
44 | valid-jsdoc:
45 | - error
46 | - requireReturn: false
47 | yoda: error
48 |
--------------------------------------------------------------------------------
/iot-perishable-network/.eslintrc.yml:
--------------------------------------------------------------------------------
1 | env:
2 | es6: false
3 | node: true
4 | mocha: true
5 | extends: 'eslint:recommended'
6 | parserOptions:
7 | ecmaVersion: 2015
8 | sourceType:
9 | - script
10 | rules:
11 | indent:
12 | - error
13 | - 4
14 | linebreak-style:
15 | - error
16 | - unix
17 | quotes:
18 | - error
19 | - single
20 | semi:
21 | - error
22 | - always
23 | no-unused-vars:
24 | - error
25 | - args: none
26 | no-console: off
27 | curly: error
28 | eqeqeq: error
29 | no-throw-literal: error
30 | strict: error
31 | dot-notation: error
32 | no-tabs: error
33 | no-trailing-spaces: error
34 | no-use-before-define: error
35 | no-useless-call: error
36 | no-with: error
37 | operator-linebreak: error
38 | require-jsdoc:
39 | - error
40 | - require:
41 | ClassDeclaration: true
42 | MethodDefinition: true
43 | FunctionDeclaration: true
44 | valid-jsdoc:
45 | - error
46 | - requireReturn: false
47 | yoda: error
48 |
--------------------------------------------------------------------------------
/iot-perishable-network-advanced/.eslintrc.yml:
--------------------------------------------------------------------------------
1 | env:
2 | es6: false
3 | node: true
4 | mocha: true
5 | extends: 'eslint:recommended'
6 | parserOptions:
7 | ecmaVersion: 2015
8 | sourceType:
9 | - script
10 | rules:
11 | indent:
12 | - error
13 | - 4
14 | linebreak-style:
15 | - error
16 | - unix
17 | quotes:
18 | - error
19 | - single
20 | semi:
21 | - error
22 | - always
23 | no-unused-vars:
24 | - error
25 | - args: none
26 | no-console: off
27 | curly: error
28 | eqeqeq: error
29 | no-throw-literal: error
30 | strict: error
31 | dot-notation: error
32 | no-tabs: error
33 | no-trailing-spaces: error
34 | no-use-before-define: error
35 | no-useless-call: error
36 | no-with: error
37 | operator-linebreak: error
38 | require-jsdoc:
39 | - error
40 | - require:
41 | ClassDeclaration: true
42 | MethodDefinition: true
43 | FunctionDeclaration: true
44 | valid-jsdoc:
45 | - error
46 | - requireReturn: false
47 | yoda: error
48 |
--------------------------------------------------------------------------------
/NcaaMarchMadness/src/main/data/tourney_teams_file_2016.txt:
--------------------------------------------------------------------------------
1 | NCAA Men's Basketball
2 | DivisionITournament Participants
3 | Through Games 1/1/2016
4 |
5 | Arizona
6 | Austin Peay
7 | Baylor
8 | Buffalo
9 | Butler
10 | CSU Bakersfield
11 | California
12 | Chattanooga
13 | Cincinnati
14 | Colorado
15 | Dayton
16 | Duke
17 | FGCU
18 | Fairleigh Dickinson
19 | Fresno St
20 | Gonzaga
21 | Green Bay
22 | Hampton
23 | Hawaii
24 | Holy Cross
25 | Indiana
26 | Iona
27 | Iowa
28 | Iowa St
29 | Kansas
30 | Kentucky
31 | Little Rock
32 | Maryland
33 | Miami FL
34 | Michigan
35 | Michigan St
36 | Middle Tenn
37 | North Carolina
38 | Notre Dame
39 | Oklahoma
40 | Oregon
41 | Oregon St
42 | Pittsburgh
43 | Providence
44 | Purdue
45 | SFA
46 | Saint Josephs
47 | Seton Hall
48 | South Dakota St
49 | Southern California
50 | Southern U
51 | Stony Brook
52 | Syracuse
53 | Temple
54 | Texas
55 | Texas AM
56 | Texas Tech
57 | Tulsa
58 | UConn
59 | UNC Asheville
60 | UNCW
61 | UNI
62 | Utah
63 | VCU
64 | Vanderbilt
65 | Villanova
66 | Virginia
67 | Weber St
68 | West Virginia
69 | Wichita St
70 | Wisconsin
71 | Xavier
72 | Yale
73 |
--------------------------------------------------------------------------------
/NcaaMarchMadness/src/main/resources/network.properties:
--------------------------------------------------------------------------------
1 | #
2 | # Copyright 2017 Makoto Consulting Group, Inc.
3 | #
4 | # Licensed under the Apache License, Version 2.0 (the "License");
5 | # you may not use this file except in compliance with the License.
6 | # You may obtain a copy of the License at
7 | #
8 | # http://www.apache.org/licenses/LICENSE-2.0
9 | #
10 | # Unless required by applicable law or agreed to in writing, software
11 | # distributed under the License is distributed on an "AS IS" BASIS,
12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | # See the License for the specific language governing permissions and
14 | # limitations under the License.
15 | #
16 | # This is the one property that is absolutely required
17 | base.directory=/Users/sperry/l/MarchMadness/data
18 |
19 | #
20 | # IMPORTANT NOTE: The application has reasonable defaults for all
21 | # of its settings. ONLY put properties here that you want to override
22 | # from their defaults!
23 |
24 | randomize.momentum=no
25 |
26 | momentum.default.value=0.05
27 |
28 | epoch.break.iteration.count=5000
29 |
30 | max.network.error=0.005
31 |
32 | use.bias.neurons=false
--------------------------------------------------------------------------------
/NcaaMarchMadness/src/main/data/tourney_teams_file_2011.txt:
--------------------------------------------------------------------------------
1 | NCAA Men's Basketball
2 | DivisionITournament Participants
3 | Through Games 1/1/2011
4 |
5 | Akron
6 | Alabama St
7 | Arizona
8 | BYU
9 | Belmont
10 | Boston U
11 | Bucknell
12 | Butler
13 | Cincinnati
14 | Clemson
15 | Duke
16 | Florida
17 | Florida St
18 | George Mason
19 | Georgetown
20 | Georgia
21 | Gonzaga
22 | Hampton
23 | Illinois
24 | Indiana St
25 | Kansas
26 | Kansas St
27 | Kentucky
28 | LIU Brooklyn
29 | Little Rock
30 | Louisville
31 | Marquette
32 | Memphis
33 | Michigan
34 | Michigan St
35 | Missouri
36 | Morehead St
37 | North Carolina
38 | Northern Colo
39 | Notre Dame
40 | Oakland
41 | Ohio St
42 | Old Dominion
43 | Penn St
44 | Pittsburgh
45 | Princeton
46 | Purdue
47 | Richmond
48 | Saint Peters
49 | San Diego St
50 | Southern California
51 | St Johns NY
52 | Syracuse
53 | Temple
54 | Tennessee
55 | Texas
56 | Texas AM
57 | UAB
58 | UC Santa Barbara
59 | UCLA
60 | UConn
61 | UNC Asheville
62 | UNLV
63 | UTSA
64 | Utah St
65 | VCU
66 | Vanderbilt
67 | Villanova
68 | Washington
69 | West Virginia
70 | Wisconsin
71 | Wofford
72 | Xavier
73 |
--------------------------------------------------------------------------------
/NcaaMarchMadness/src/main/data/tourney_teams_file_2013.txt:
--------------------------------------------------------------------------------
1 | NCAA Men's Basketball
2 | DivisionITournament Participants
3 | Through Games 1/1/2013
4 |
5 | Akron
6 | Albany NY
7 | Arizona
8 | Belmont
9 | Boise St
10 | Bucknell
11 | Butler
12 | California
13 | Cincinnati
14 | Colorado
15 | Colorado St
16 | Creighton
17 | Davidson
18 | Duke
19 | FGCU
20 | Florida
21 | Georgetown
22 | Gonzaga
23 | Harvard
24 | Illinois
25 | Indiana
26 | Iona
27 | Iowa St
28 | James Madison
29 | Kansas
30 | Kansas St
31 | LIU Brooklyn
32 | La Salle
33 | Liberty
34 | Louisville
35 | Marquette
36 | Memphis
37 | Miami FL
38 | Michigan
39 | Michigan St
40 | Middle Tenn
41 | Minnesota
42 | Missouri
43 | Montana
44 | NC AT
45 | NC State
46 | New Mexico
47 | New Mexico St
48 | North Carolina
49 | Northwestern St
50 | Notre Dame
51 | Ohio St
52 | Oklahoma
53 | Oklahoma St
54 | Ole Miss
55 | Oregon
56 | Pacific
57 | Pittsburgh
58 | Saint Louis
59 | Saint Marys CA
60 | San Diego St
61 | South Dakota St
62 | Southern U
63 | Syracuse
64 | Temple
65 | UCLA
66 | UNLV
67 | VCU
68 | Valparaiso
69 | Villanova
70 | Western Ky
71 | Wichita St
72 | Wisconsin
73 |
--------------------------------------------------------------------------------
/NcaaMarchMadness/src/main/data/tourney_teams_file_2014.txt:
--------------------------------------------------------------------------------
1 | NCAA Men's Basketball
2 | DivisionITournament Participants
3 | Through Games 1/1/2014
4 |
5 | Albany NY
6 | American
7 | Arizona
8 | Arizona St
9 | BYU
10 | Baylor
11 | Cal Poly
12 | Cincinnati
13 | Coastal Caro
14 | Colorado
15 | Creighton
16 | Dayton
17 | Delaware
18 | Duke
19 | Eastern Ky
20 | Florida
21 | George Washington
22 | Gonzaga
23 | Harvard
24 | Iowa
25 | Iowa St
26 | Kansas
27 | Kansas St
28 | Kentucky
29 | Lafayette
30 | Louisville
31 | Manhattan
32 | Massachusetts
33 | Memphis
34 | Mercer
35 | Michigan
36 | Michigan St
37 | Milwaukee
38 | Mt St Marys
39 | NC Central
40 | NC State
41 | Nebraska
42 | New Mexico
43 | New Mexico St
44 | North Carolina
45 | North Dakota St
46 | Ohio St
47 | Oklahoma
48 | Oklahoma St
49 | Oregon
50 | Pittsburgh
51 | Providence
52 | SFA
53 | Saint Josephs
54 | Saint Louis
55 | San Diego St
56 | Stanford
57 | Syracuse
58 | Tennessee
59 | Texas
60 | Texas Southern
61 | Tulsa
62 | UCLA
63 | UConn
64 | VCU
65 | Villanova
66 | Virginia
67 | Weber St
68 | Western Mich
69 | Wichita St
70 | Wisconsin
71 | Wofford
72 | Xavier
73 |
--------------------------------------------------------------------------------
/NcaaMarchMadness/src/main/data/tourney_teams_file_2012.txt:
--------------------------------------------------------------------------------
1 | NCAA Men's Basketball
2 | DivisionITournament Participants
3 | Through Games 1/1/2012
4 |
5 | Alabama
6 | BYU
7 | Baylor
8 | Belmont
9 | California
10 | Cincinnati
11 | Colorado
12 | Colorado St
13 | Creighton
14 | Davidson
15 | Detroit Mercy
16 | Duke
17 | Florida
18 | Florida St
19 | Georgetown
20 | Gonzaga
21 | Harvard
22 | Indiana
23 | Iona
24 | Iowa St
25 | Kansas
26 | Kansas St
27 | Kentucky
28 | LIU Brooklyn
29 | Lamar University
30 | Lehigh
31 | Long Beach St
32 | Louisville
33 | Loyola Maryland
34 | Marquette
35 | Memphis
36 | Michigan
37 | Michigan St
38 | Mississippi Val
39 | Missouri
40 | Montana
41 | Murray St
42 | NC State
43 | New Mexico
44 | New Mexico St
45 | Norfolk St
46 | North Carolina
47 | Notre Dame
48 | Ohio
49 | Ohio St
50 | Purdue
51 | Saint Louis
52 | Saint Marys CA
53 | San Diego St
54 | South Dakota St
55 | South Fla
56 | Southern Miss
57 | St Bonaventure
58 | Syracuse
59 | Temple
60 | Texas
61 | UConn
62 | UNC Asheville
63 | UNLV
64 | VCU
65 | Vanderbilt
66 | Vermont
67 | Virginia
68 | West Virginia
69 | Western Ky
70 | Wichita St
71 | Wisconsin
72 | Xavier
73 |
--------------------------------------------------------------------------------
/NcaaMarchMadness/src/main/java/com/makotojava/ncaabb/dao/TournamentAnalyticsDao.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2017 Makoto Consulting Group, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.makotojava.ncaabb.dao;
17 |
18 | import com.makotojava.ncaabb.model.TournamentAnalytics;
19 |
20 | /**
21 | * Data Access Object for TournamentAnalytics model data.
22 | *
23 | * @author sperry
24 | *
25 | */
26 | public interface TournamentAnalyticsDao {
27 |
28 | /**
29 | * Retrieves the TournamentAnalytics associated with the specified year.
30 | *
31 | * @param year
32 | *
33 | * @return
34 | */
35 | public TournamentAnalytics fetchByYear(Integer year);
36 |
37 | }
38 |
--------------------------------------------------------------------------------
/NcaaMarchMadness/src/main/java/com/makotojava/ncaabb/dao/SeasonAnalyticsDao.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2017 Makoto Consulting Group, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.makotojava.ncaabb.dao;
17 |
18 | import com.makotojava.ncaabb.model.SeasonAnalytics;
19 |
20 | /**
21 | * Data Access Object interface for SeasonAnalytics model data.
22 | *
23 | * @author J Steven Perry
24 | *
25 | */
26 | public interface SeasonAnalyticsDao {
27 |
28 | /**
29 | * Retrieves SeasonAnalytics object for the specified year.
30 | *
31 | * @param year
32 | * The specified year.
33 | *
34 | * @return The SeasonAnalytics object
35 | */
36 | public SeasonAnalytics fetchByYear(Integer year);
37 |
38 | }
39 |
--------------------------------------------------------------------------------
/NcaaMarchMadness/src/main/sql/find_missing_team_names.sql:
--------------------------------------------------------------------------------
1 | --
2 | -- Run this script against the DB to make sure you do not have
3 | -- any teams in the tournament_participant table that do not match
4 | -- the season data.
5 | --
6 | -- This should not be an issue, since I've cleaned up the data
7 | -- up to 2016, but until then, the team names from the tournament
8 | -- results I had to manually enter (from Google search, etc) team
9 | -- did not always match the team names from the downloaded data
10 | -- from the NCAA web site.
11 | --
12 | -- For example, a common mismatch was ASU (from USA Today), when
13 | -- it should have been Arizona St (from NCAA data).
14 | --
15 | -- If you manually enter tournament results data after 2016
16 | -- (i.e., after I plan to release this code into the wild), this
17 | -- could be an issue for you, depending on where you get the data.
18 | --
19 | -- Check out the script correct_missing_team_names.sql, which
20 | -- I used to fix this as I was getting all this lined out.
21 | --
22 | select distinct year, missing_team_name from (
23 | select tp.year, tp.team_name as missing_team_name
24 | from tournament_participant tp
25 | left outer join
26 | scoring_offense so on tp.team_name = so.team_name and tp.year = so.year
27 | where so.team_name is null
28 |
29 | union
30 |
31 | select tr.year, tr.winning_team_name as missing_team_name
32 | from tournament_result tr
33 | left outer join
34 | scoring_offense so on tr.winning_team_name = so.team_name and tr.year = so.year
35 | where so.team_name is null
36 |
37 | union
38 |
39 | select tr.year, tr.losing_team_name as missing_team_name
40 | from tournament_result tr
41 | left outer join
42 | scoring_offense so on tr.losing_team_name = so.team_name and tr.year = so.year
43 | where so.team_name is null
44 | ) nested
45 | order by 1, 2
46 | ;
--------------------------------------------------------------------------------
/NcaaMarchMadness/src/main/java/com/makotojava/ncaabb/dao/TournamentResultDao.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2017 Makoto Consulting Group, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.makotojava.ncaabb.dao;
17 |
18 | import java.util.List;
19 |
20 | import com.makotojava.ncaabb.model.TournamentResult;
21 |
22 | /**
23 | * Data Access Object interface for {@link TournamentResult} model data.
24 | *
25 | * @author J Steven Perry
26 | *
27 | */
28 | public interface TournamentResultDao {
29 |
30 | /**
31 | * Fetch all {@link TournamentResult} objects by the specified year
32 | * and return a List. The List
33 | * will be empty if no {@link TournamentResult} objects could be found for
34 | * the specified year (which probably means you forgot to load the
35 | * data into the DB, shame, shame, shame).
36 | *
37 | * @param year
38 | * The year for which {@link TournamentResult} objects are to be
39 | * fetched.
40 | * @return List - the List of
41 | * {@link TournamentResult} objects if they could be located, or an empty list
42 | * if not.
43 | */
44 | public List fetchAllByYear(Integer year);
45 |
46 | }
47 |
--------------------------------------------------------------------------------
/NcaaMarchMadness/src/main/java/com/makotojava/ncaabb/sqlgenerator/Strategy.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2017 Makoto Consulting Group, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.makotojava.ncaabb.sqlgenerator;
17 |
18 | import java.util.List;
19 |
20 | /**
21 | * Strategy pattern interface.
22 | *
23 | * See: https://en.wikipedia.org/wiki/Strategy_pattern
24 | *
25 | * @author sperry
26 | *
27 | */
28 | public interface Strategy {
29 | /**
30 | * Generates SQL for the Statistics Category associated with
31 | * the Strategy implementation.
32 | *
33 | * @param year
34 | * The tournament year the SQL is to be generated for.
35 | *
36 | * @param data
37 | * The data to be inserted via SQL.
38 | *
39 | * @return String - the SQL INSERT statements to massage the specified
40 | * data into the DB.
41 | */
42 | String generateSql(String year, List data);
43 |
44 | /**
45 | * Returns the name of the Strategy implementation.
46 | *
47 | * @return String - the name of this Strategy implementation.
48 | */
49 | String getStrategyName();
50 |
51 | /**
52 | * Returns the number of rows processed by this Strategy.
53 | *
54 | * @return int - the number of rows processed
55 | */
56 | int getNumberOfRowsProcessed();
57 |
58 | }
--------------------------------------------------------------------------------
/NcaaMarchMadness/src/test/java/com/makotojava/ncaabb/generation/MlpNetworkTrainerTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2017 Makoto Consulting Group, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.makotojava.ncaabb.generation;
17 |
18 | import static org.junit.jupiter.api.Assertions.assertArrayEquals;
19 |
20 | import org.junit.jupiter.api.Test;
21 | import org.junit.platform.runner.JUnitPlatform;
22 | import org.junit.runner.RunWith;
23 |
24 | @RunWith(JUnitPlatform.class)
25 | public class MlpNetworkTrainerTest {
26 |
27 | @Test
28 | public void testComputeYearsToTrain() {
29 | //
30 | String[] args = {
31 | "2010", "2011", "2012", "2013,2014"
32 | };
33 | Integer[] expectedYearsToTrain = {
34 | 2010, 2011, 2012
35 | };
36 | Integer[] actualYearsToTrain = MlpNetworkTrainer.computeYearsToTrain(args);
37 | assertArrayEquals(expectedYearsToTrain, actualYearsToTrain);
38 | }
39 |
40 | @Test
41 | public void testComputeYearsToSimulate() {
42 | //
43 | String[] args = {
44 | "2010", "2011", "2012", "2013,2014"
45 | };
46 | Integer[] expectedYearsToSimulate = {
47 | 2013, 2014
48 | };
49 | Integer[] actualYearsToSimulate = MlpNetworkTrainer.computeYearsToSimulate(args);
50 | assertArrayEquals(expectedYearsToSimulate, actualYearsToSimulate);
51 | }
52 |
53 | }
54 |
--------------------------------------------------------------------------------
/NcaaMarchMadness/src/main/java/com/makotojava/ncaabb/model/TournamentAnalytics.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2017 Makoto Consulting Group, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.makotojava.ncaabb.model;
17 |
18 | /**
19 | * This class represents the view:
20 | *
21 | * View "public.v_tournament_analytics"
22 | * Column | Type | Modifiers
23 | * -----------+---------+-----------
24 | * year | integer |
25 | * min_score | integer |
26 | * max_score | integer |
27 | *
28 | * @author sperry
29 | *
30 | */
31 | public class TournamentAnalytics implements Comparable {
32 |
33 | private Integer year;
34 | private Integer minScore;
35 | private Integer maxScore;
36 |
37 | /**
38 | * Constructor
39 | */
40 | public TournamentAnalytics() {
41 | // Nothing to do
42 | }
43 |
44 | @Override
45 | public int compareTo(TournamentAnalytics o) {
46 | return getYear().compareTo(o.getYear());
47 | }
48 |
49 | public Integer getYear() {
50 | return year;
51 | }
52 |
53 | public void setYear(Integer year) {
54 | this.year = year;
55 | }
56 |
57 | public Integer getMinScore() {
58 | return minScore;
59 | }
60 |
61 | public void setMinScore(Integer minScore) {
62 | this.minScore = minScore;
63 | }
64 |
65 | public Integer getMaxScore() {
66 | return maxScore;
67 | }
68 |
69 | public void setMaxScore(Integer maxScore) {
70 | this.maxScore = maxScore;
71 | }
72 |
73 | }
74 |
--------------------------------------------------------------------------------
/NcaaMarchMadness/src/main/java/com/makotojava/ncaabb/simulation/NetworkRunner.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2017 Makoto Consulting Group, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.makotojava.ncaabb.simulation;
17 |
18 | import java.util.List;
19 |
20 | import org.neuroph.core.NeuralNetwork;
21 | import org.neuroph.nnet.learning.BackPropagation;
22 |
23 | /**
24 | * Interface implemented by any class whose job it is to run a network.
25 | *
26 | * @author J Steven Perry
27 | *
28 | * @param
29 | * - The implementation class, must be a NeuralNetwork with
30 | * BackPropagation learning rule.
31 | */
32 | public interface NetworkRunner> {
33 |
34 | /**
35 | * Loads all of the networks to be used. It is up to the implementation
36 | * to decide where these networks are stored, and this method encapsulates
37 | * callers from that.
38 | *
39 | * @return List - a List of the networks to be used.
40 | */
41 | public List loadNetworks();
42 |
43 | /**
44 | * Run the specified network using the specified normalized input data.
45 | *
46 | * @param network
47 | * The Network to be run
48 | *
49 | * @param input
50 | * The input data. Must be normalized or the results will
51 | * be unpredictable.
52 | *
53 | * @return The output data. The exact format depends on the network
54 | * that is run.
55 | */
56 | public double[] runNetwork(T network, double[] input);
57 | }
58 |
--------------------------------------------------------------------------------
/perishable-network/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "engines": {
3 | "composer": "^0.15.0"
4 | },
5 | "name": "perishable-network",
6 | "version": "0.1.11",
7 | "description": "Shipping Perishable Goods Business Network",
8 | "networkImage": "https://github.com/makotogo/developerWorks/perishable-network/networkimage.svg",
9 | "networkImageanimated": "https://github.com/makotogo/developerWorks/perishable-network/networkimageanimated.svg",
10 | "scripts": {
11 | "clean": "rm -Rf ./node_modules ./dist ./composer-logs ./out",
12 | "prepublish": "mkdirp ./dist && composer archive create --sourceType dir --sourceName . -a ./dist/perishable-network.bna",
13 | "pretest": "npm run lint",
14 | "lint": "eslint .",
15 | "postlint": "npm run licchk",
16 | "licchk": "license-check",
17 | "postlicchk": "npm run doc",
18 | "doc": "jsdoc --pedantic --recurse -c jsdoc.json",
19 | "test": "mocha -t 0 --recursive",
20 | "deploy": "./scripts/deploy.sh"
21 | },
22 | "repository": {
23 | "type": "git",
24 | "url": "https://github.com/makotogo/developerWorks.git"
25 | },
26 | "keywords": [
27 | "shipping",
28 | "goods",
29 | "perishable",
30 | "composer",
31 | "composer-network",
32 | "iot"
33 | ],
34 | "author": "Hyperledger Composer",
35 | "license": "Apache-2.0",
36 | "devDependencies": {
37 | "browserfs": "^1.2.0",
38 | "chai": "^3.5.0",
39 | "composer-admin": "^0.14.0-0",
40 | "composer-cli": "^0.14.0-0",
41 | "composer-client": "^0.14.0-0",
42 | "composer-connector-embedded": "^0.14.0-0",
43 | "eslint": "^3.6.1",
44 | "istanbul": "^0.4.5",
45 | "jsdoc": "^3.4.1",
46 | "license-check": "^1.1.5",
47 | "mkdirp": "^0.5.1",
48 | "mocha": "^3.2.0",
49 | "moment": "^2.17.1"
50 | },
51 | "license-check-config": {
52 | "src": [
53 | "**/*.js",
54 | "!./coverage/**/*",
55 | "!./node_modules/**/*",
56 | "!./out/**/*",
57 | "!./scripts/**/*"
58 | ],
59 | "path": "header.txt",
60 | "blocking": true,
61 | "logInfo": false,
62 | "logError": true
63 | }
64 | }
65 |
--------------------------------------------------------------------------------
/NcaaMarchMadness/src/main/java/com/makotojava/ncaabb/generation/Networks.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2017 Makoto Consulting Group, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.makotojava.ncaabb.generation;
17 |
18 | /**
19 | * This class is used to specify the hidden layers of the networks
20 | * to be used. The name is probably misleading (Networks).
21 | *
22 | * The NETWORKS constant defines several networks' hidden layers only.
23 | * The input and output layers are defined elsewhere.
24 | *
25 | *
26 | *
27 | * @author sperry
28 | *
29 | */
30 | public class Networks {
31 |
32 | private static final int[][] NETWORKS = {
33 | // Two hidden layers
34 | // { 90, 16 },
35 | // { 20, 10 },
36 | // { 23, 13 },
37 | // Three hidden layers
38 | { 90, 30, 20 },
39 | { 20, 30, 10 },
40 | { 23, 31, 11 },
41 | // // Four hidden layers
42 | { 90, 30, 120, 20 },
43 | { 90, 55, 20, 15 },
44 | // { 30, 55, 20, 15 },
45 | // { 23, 16, 12, 6 },
46 | // { 20, 35, 10, 5 },
47 | // { 22, 37, 13, 5 },
48 | // Five hidden layers
49 | { 90, 30, 60, 20, 15 },
50 | // { 35, 20, 40, 15, 10 },
51 | // { 30, 25, 40, 15, 10 },
52 | // { 33, 23, 43, 13, 11 },
53 | // Six hidden layers
54 | { 90, 35, 20, 50, 15 },
55 | // { 35, 45, 25, 30, 20, 10 },
56 | // { 25, 35, 15, 20, 10, 15 },
57 | // { 27, 33, 17, 21, 11, 17 },
58 | };
59 |
60 | public static int[][] getNetworks() {
61 | return NETWORKS;
62 | }
63 |
64 | }
65 |
--------------------------------------------------------------------------------
/iot-perishable-network-advanced/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "engines": {
3 | "composer": "^0.15.0"
4 | },
5 | "name": "iot-perishable-network-advanced",
6 | "version": "0.1.13",
7 | "description": "Advanced Perishable Goods Business Network",
8 | "networkImage": "https://github.com/makotogo/developerWorks/iot-perishable-network-advanced/networkimage.svg",
9 | "networkImageanimated": "https://github.com/makotogo/developerWorks/iot-perishable-network-advanced/networkimageanimated.svg",
10 | "scripts": {
11 | "clean": "rm -Rf ./node_modules ./dist ./composer-logs ./out",
12 | "prepublish": "mkdirp ./dist && composer archive create --sourceType dir --sourceName . -a ./dist/iot-perishable-network-advanced.bna",
13 | "pretest": "npm run lint",
14 | "lint": "eslint .",
15 | "postlint": "npm run licchk",
16 | "licchk": "license-check",
17 | "postlicchk": "npm run doc",
18 | "doc": "jsdoc --pedantic --recurse -c jsdoc.json",
19 | "test": "mocha -t 0 --recursive && cucumber-js",
20 | "deploy": "./scripts/deploy.sh"
21 | },
22 | "repository": {
23 | "type": "git",
24 | "url": "https://github.com/makotogo/developerWorks.git"
25 | },
26 | "keywords": [
27 | "shipping",
28 | "goods",
29 | "perishable",
30 | "composer",
31 | "composer-network",
32 | "iot"
33 | ],
34 | "author": "J Steven Perry",
35 | "license": "Apache-2.0",
36 | "devDependencies": {
37 | "browserfs": "^1.2.0",
38 | "chai": "^3.5.0",
39 | "composer-admin": "^0.14.0-0",
40 | "composer-cli": "^0.14.0-0",
41 | "composer-client": "^0.14.0-0",
42 | "composer-connector-embedded": "^0.14.0-0",
43 | "composer-cucumber-steps": "^0.14.0-0",
44 | "cucumber": "^2.2.0",
45 | "eslint": "^3.6.1",
46 | "istanbul": "^0.4.5",
47 | "jsdoc": "^3.4.1",
48 | "license-check": "^1.1.5",
49 | "mkdirp": "^0.5.1",
50 | "mocha": "^3.2.0",
51 | "moment": "^2.17.1"
52 | },
53 | "license-check-config": {
54 | "src": [
55 | "**/*.js",
56 | "!./coverage/**/*",
57 | "!./node_modules/**/*",
58 | "!./out/**/*",
59 | "!./scripts/**/*"
60 | ],
61 | "path": "header.txt",
62 | "blocking": true,
63 | "logInfo": false,
64 | "logError": true
65 | }
66 | }
67 |
--------------------------------------------------------------------------------
/iot-perishable-network/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "engines": {
3 | "composer": "^0.15.0"
4 | },
5 | "name": "iot-perishable-network",
6 | "version": "0.1.12",
7 | "description": "Shipping Perishable Goods Business Network",
8 | "networkImage": "https://github.com/makotogo/developerWorks/iot-perishable-network/networkimage.svg",
9 | "networkImageanimated": "https://github.com/makotogo/developerWorks/iot-perishable-network/networkimageanimated.svg",
10 | "scripts": {
11 | "clean": "rm -Rf ./node_modules ./dist ./composer-logs ./out",
12 | "prepublish": "mkdirp ./dist && composer archive create --sourceType dir --sourceName . -a ./dist/iot-perishable-network.bna",
13 | "pretest": "npm run lint",
14 | "lint": "eslint .",
15 | "postlint": "npm run licchk",
16 | "licchk": "license-check",
17 | "postlicchk": "npm run doc",
18 | "doc": "jsdoc --pedantic --recurse -c jsdoc.json",
19 | "test": "mocha -t 0 --recursive && cucumber-js",
20 | "deploy": "./scripts/deploy.sh"
21 | },
22 | "repository": {
23 | "type": "git",
24 | "url": "https://github.com/makotogo/developerWorks.git"
25 | },
26 | "keywords": [
27 | "shipping",
28 | "goods",
29 | "perishable",
30 | "composer",
31 | "composer-network",
32 | "iot"
33 | ],
34 | "author": "Hyperledger Composer",
35 | "license": "Apache-2.0",
36 | "devDependencies": {
37 | "browserfs": "^1.2.0",
38 | "chai": "^3.5.0",
39 | "chai-as-promised": "^6.0.0",
40 | "composer-admin": "^0.14.0-0",
41 | "composer-cli": "^0.14.0-0",
42 | "composer-client": "^0.14.0-0",
43 | "composer-connector-embedded": "^0.14.0-0",
44 | "composer-cucumber-steps": "^0.14.0-0",
45 | "cucumber": "^2.2.0",
46 | "eslint": "^3.6.1",
47 | "istanbul": "^0.4.5",
48 | "jsdoc": "^3.5.5",
49 | "license-check": "^1.1.5",
50 | "mkdirp": "^0.5.1",
51 | "mocha": "^3.2.0",
52 | "moment": "^2.17.1",
53 | "nyc": "^11.0.2"
54 | },
55 | "license-check-config": {
56 | "src": [
57 | "**/*.js",
58 | "!./coverage/**/*",
59 | "!./node_modules/**/*",
60 | "!./out/**/*",
61 | "!./scripts/**/*"
62 | ],
63 | "path": "header.txt",
64 | "blocking": true,
65 | "logInfo": false,
66 | "logError": true
67 | }
68 | }
69 |
--------------------------------------------------------------------------------
/NcaaMarchMadness/src/main/java/com/makotojava/ncaabb/sqlgenerator/TournamentParticipant.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2017 Makoto Consulting Group, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.makotojava.ncaabb.sqlgenerator;
17 |
18 | import java.util.List;
19 |
20 | import org.apache.commons.lang3.StringUtils;
21 | import org.apache.log4j.Logger;
22 |
23 | public class TournamentParticipant extends AbstractStrategy {
24 |
25 | private static final Logger LOG = Logger.getLogger(TournamentResult.class);
26 |
27 | public static final String TABLE_NAME = "tournament_participant";
28 |
29 | public final static String STATCAT_TOURNAMENT_PARTICIPANT = "Tournament Participants";
30 |
31 | public TournamentParticipant() {
32 | super(TournamentParticipant.STATCAT_TOURNAMENT_PARTICIPANT);
33 | }
34 |
35 | @Override
36 | public String generateSql(String year, List data) {
37 | StringBuilder sb = new StringBuilder();
38 | LOG.debug("Generating SQL for stat cat => " + getStrategyName() + " and year => " + year);
39 | LOG.debug("There are " + data.size() + " lines of data to be processed...");
40 | for (String[] line : data) {
41 | String teamName = StringUtils.strip(line[0]);
42 | // Now for the SQL...
43 | String sql = "INSERT INTO " + /* SCHEMA_NAME + "." + */TABLE_NAME + "(" +
44 | // YEAR INTEGER NOT NULL,
45 | // TEAM_NAME VARCHAR(64) NOT NULL
46 | "YEAR, TEAM_NAME"
47 | + ") "
48 | + "VALUES(" +
49 | Integer.valueOf(year) + ", " +
50 | "'" + teamName + "'" +
51 | ");" + "\n";
52 | sb.append(sql);
53 | incrementNumberOfRowsProcessed();
54 | }
55 | return sb.toString();
56 | }
57 |
58 | }
59 |
--------------------------------------------------------------------------------
/NcaaMarchMadness/src/main/java/com/makotojava/ncaabb/sqlgenerator/AbstractStrategy.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2017 Makoto Consulting Group, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.makotojava.ncaabb.sqlgenerator;
17 |
18 | import java.time.LocalDate;
19 | import java.time.ZoneOffset;
20 | import java.time.format.DateTimeFormatter;
21 | import java.util.Date;
22 |
23 | import org.apache.commons.lang3.StringUtils;
24 |
25 | public abstract class AbstractStrategy implements Strategy {
26 |
27 | private String strategyName;
28 | private int numberOfRowsProcessed;
29 |
30 | public AbstractStrategy(String strategyName) {
31 | setStrategyName(strategyName);
32 | }
33 |
34 | @Override
35 | public String getStrategyName() {
36 | return strategyName;
37 | }
38 |
39 | private void setStrategyName(String value) {
40 | if (StringUtils.isEmpty(value)) {
41 | throw new IllegalArgumentException("Strategy Name cannot be empty or null!");
42 | } else {
43 | strategyName = value;
44 | }
45 | }
46 |
47 | @Override
48 | public int getNumberOfRowsProcessed() {
49 | return numberOfRowsProcessed;
50 | }
51 |
52 | protected void incrementNumberOfRowsProcessed() {
53 | numberOfRowsProcessed++;
54 | }
55 |
56 | protected Date convertStringToDate(String dateAsString) {
57 | return convertStringToDate(dateAsString, "M/d/yy");
58 | }
59 |
60 | protected Date convertStringToDate(String dateAsString, String pattern) {
61 | Date ret = null;
62 | DateTimeFormatter dtf = DateTimeFormatter.ofPattern(pattern);
63 | LocalDate localDate = LocalDate.parse(dateAsString, dtf);
64 |
65 | ret = Date.from(localDate.atStartOfDay(ZoneOffset.systemDefault()).toInstant());
66 |
67 | return ret;
68 | }
69 |
70 | }
71 |
--------------------------------------------------------------------------------
/perishable-network/README.md:
--------------------------------------------------------------------------------
1 | # Perishable Goods Network
2 |
3 | > Example business network that shows growers, shippers and importers defining contracts for the price of perishable goods, based on temperature readings received for shipping containers.
4 |
5 | The business network defines a contract between growers and importers. The contract stipulates that: On receipt of the shipment the importer pays the grower the unit price x the number of units in the shipment. Shipments that arrive late are free. Shipments that have breached the low temperate threshold have a penalty applied proportional to the magnitude of the breach x a penalty factor. Shipments that have breached the high temperate threshold have a penalty applied proportional to the magnitude of the breach x a penalty factor.
6 |
7 | This business network defines:
8 |
9 | **Participants**
10 | `Grower` `Importer` `Shipper`
11 |
12 | **Assets**
13 | `Contract` `Shipment`
14 |
15 | **Transactions**
16 | `TemperatureReading` `ShipmentReceived` `SetupDemo`
17 |
18 | To test this Business Network Definition in the **Test** tab:
19 |
20 | Submit a `SetupDemo` transaction:
21 |
22 | ```
23 | {
24 | "$class": "org.acme.shipping.perishable.SetupDemo"
25 | }
26 | ```
27 |
28 | This transaction populates the Participant Registries with a `Grower`, an `Importer` and a `Shipper`. The Asset Registries will have a `Contract` asset and a `Shipment` asset.
29 |
30 | Submit a `TemperatureReading` transaction:
31 |
32 | ```
33 | {
34 | "$class": "org.acme.shipping.perishable.TemperatureReading",
35 | "centigrade": 8,
36 | "shipment": "resource:org.acme.shipping.perishable.Shipment#SHIP_001"
37 | }
38 | ```
39 |
40 | If the temperature reading falls outside the min/max range of the contract, the price received by the grower will be reduced. You may submit several readings if you wish. Each reading will be aggregated within `SHIP_001` Shipment Asset Registry.
41 |
42 | Submit a `ShipmentReceived` transaction for `SHIP_001` to trigger the payout to the grower, based on the parameters of the `CON_001` contract:
43 |
44 | ```
45 | {
46 | "$class": "org.acme.shipping.perishable.ShipmentReceived",
47 | "shipment": "resource:org.acme.shipping.perishable.Shipment#SHIP_001"
48 | }
49 | ```
50 |
51 | If the date-time of the `ShipmentReceived` transaction is after the `arrivalDateTime` on `CON_001` then the grower will no receive any payment for the shipment.
52 |
53 | Congratulations!
54 |
--------------------------------------------------------------------------------
/NcaaMarchMadness/src/main/java/com/makotojava/ncaabb/sqlgenerator/ScoringOffense.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2017 Makoto Consulting Group, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.makotojava.ncaabb.sqlgenerator;
17 |
18 | import java.math.BigDecimal;
19 | import java.math.RoundingMode;
20 | import java.util.List;
21 |
22 | import org.apache.log4j.Logger;
23 |
24 | public class ScoringOffense extends AbstractStrategy {
25 |
26 | private static final Logger LOG = Logger.getLogger(ScoringOffense.class);
27 |
28 | public static final String TABLE_NAME = "scoring_offense";
29 |
30 | public final static String STATCAT_SCORING_OFFENSE = "Scoring Offense";
31 |
32 | public ScoringOffense() {
33 | super(ScoringOffense.STATCAT_SCORING_OFFENSE);
34 | }
35 |
36 | @Override
37 | public String generateSql(String year, List data) {
38 | //
39 | StringBuilder sb = new StringBuilder();
40 | LOG.debug("Generating SQL for stat cat => " + getStrategyName() + " and year => " + year);
41 | LOG.debug("There are " + data.size() + " lines of data to be processed...");
42 | for (String[] line : data) {
43 | String teamName = line[1];
44 | int numGames = Integer.valueOf(line[2]);
45 | int numPoints = Integer.valueOf(line[4]);
46 | BigDecimal AvergePointsPerGame = BigDecimal.valueOf((double)numPoints/numGames).setScale(5, RoundingMode.HALF_UP);
47 | String sql = "INSERT INTO " + /*SCHEMA_NAME + "." +*/ TABLE_NAME + "(" +
48 | "YEAR, TEAM_NAME, NUM_GAMES, NUM_POINTS, AVG_POINTS_PER_GAME)"
49 | + "VALUES(" +
50 | Integer.valueOf(year) + "," +
51 | "'" + teamName + "'," +
52 | numGames + "," +
53 | numPoints + "," +
54 | AvergePointsPerGame.doubleValue() +
55 | ");" + "\n"
56 | ;
57 | sb.append(sql);
58 | incrementNumberOfRowsProcessed();
59 | }
60 | return sb.toString();
61 | }
62 |
63 | }
64 |
--------------------------------------------------------------------------------
/NcaaMarchMadness/src/main/script/run-tournament-simulator.sh:
--------------------------------------------------------------------------------
1 | #!
2 | #
3 | # Script to run the TournamentSimulator program.
4 | #
5 | # Set DEBUG to something other than true to turn it off
6 | DEBUG=true
7 |
8 | function usage {
9 | echo "Usage: $0 year"
10 | echo "Description: runs a tournament simulation for the specified year"
11 | echo "Where:"
12 | echo -e "\tyear is the year for which the tournament matrix is to be created."
13 | echo "Examples:"
14 | echo "Create tournament simulation matrix for 2010:"
15 | echo -e "\t$0 2010"
16 | echo
17 | }
18 |
19 | # Process number of arguments
20 | NUMARGS=$#
21 | if [ "$DEBUG" == "true" ]; then echo -e \\n"Number of arguments: $NUMARGS"; fi
22 | if [ "$NUMARGS" -eq 0 ]; then
23 | usage
24 | exit 1
25 | fi
26 | if [ "$DEBUG" == "true" ]; then echo "Script arguments: $@"; fi
27 |
28 | # Below is an example that works on my Mac.
29 | # Change this to match your source location.
30 | ROOT_DIR=/Users/sperry/home/development/projects/developerWorks/NcaaMarchMadness
31 |
32 | # Make sure ROOT_DIR is set or bail out
33 | if [ -z "$ROOT_DIR" ]
34 | then
35 | echo "ROOT_DIR is not set! This variable should be set to the source root of your project."
36 | echo "Make sure that you run a Maven build to create the necessary class files"
37 | echo "and library dependencies"
38 | exit 1
39 | fi
40 |
41 | if [ "$DEBUG" == "true" ]; then echo "ROOT_DIR = ${ROOT_DIR}"; fi
42 |
43 | # Set the lib directory as a convenience
44 | LIB_DIR=$ROOT_DIR/target/lib
45 |
46 | SPRING_FRAMEWORK_VERSION=4.3.6.RELEASE
47 |
48 | # Set the CLASSPATH to use.
49 | CP=\
50 | $LIB_DIR/neuroph-2.94.jar:\
51 | $LIB_DIR/postgresql-9.1-901-1.jdbc4.jar:\
52 | $LIB_DIR/commons-lang3-3.4.jar:\
53 | $LIB_DIR/spring-context-$SPRING_FRAMEWORK_VERSION.jar:\
54 | $LIB_DIR/spring-core-$SPRING_FRAMEWORK_VERSION.jar:\
55 | $LIB_DIR/spring-beans-$SPRING_FRAMEWORK_VERSION.jar:\
56 | $LIB_DIR/spring-aop-$SPRING_FRAMEWORK_VERSION.jar:\
57 | $LIB_DIR/spring-expression-$SPRING_FRAMEWORK_VERSION.jar:\
58 | $LIB_DIR/spring-jdbc-$SPRING_FRAMEWORK_VERSION.jar:\
59 | $LIB_DIR/spring-tx-$SPRING_FRAMEWORK_VERSION.jar:\
60 | $LIB_DIR/log4j-1.2.17.jar:\
61 | $LIB_DIR/jcl-over-slf4j-1.7.22.jar:\
62 | $LIB_DIR/slf4j-api-1.7.22.jar:\
63 | $LIB_DIR/logback-core-1.1.9.jar:\
64 | $LIB_DIR/logback-classic-1.1.9.jar:\
65 | $LIB_DIR/opencsv-3.6.jar:
66 |
67 | if [ "$DEBUG" == "true" ]; then echo "CLASSPATH = $CP"; fi
68 |
69 | # Fire up the program
70 | java -cp $CP:$ROOT_DIR/target/classes com.makotojava.ncaabb.simulation.TournamentMatrixPredictor $@
--------------------------------------------------------------------------------
/NcaaMarchMadness/src/main/java/com/makotojava/ncaabb/sqlgenerator/ScoringDefense.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2017 Makoto Consulting Group, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.makotojava.ncaabb.sqlgenerator;
17 |
18 | import java.math.BigDecimal;
19 | import java.math.RoundingMode;
20 | import java.util.List;
21 |
22 | import org.apache.log4j.Logger;
23 |
24 | public class ScoringDefense extends AbstractStrategy {
25 |
26 | private static final Logger LOG = Logger.getLogger(ScoringDefense.class);
27 |
28 | public static final String TABLE_NAME = "scoring_defense";
29 |
30 | public final static String STATCAT_SCORING_DEFENSE = "Scoring Defense";
31 |
32 | public ScoringDefense() {
33 | super(ScoringDefense.STATCAT_SCORING_DEFENSE);
34 | }
35 |
36 | @Override
37 | public String generateSql(String year, List data) {
38 | //
39 | StringBuilder sb = new StringBuilder();
40 | LOG.debug("Generating SQL for stat cat => " + getStrategyName() + " and year => " + year);
41 | LOG.debug("There are " + data.size() + " lines of data to be processed...");
42 | for (String[] line : data) {
43 | String teamName = line[1];
44 | int numGames = Integer.valueOf(line[2]);
45 | int numPoints = Integer.valueOf(line[4]);
46 | BigDecimal AvergePointsPerGame = BigDecimal.valueOf((double)numPoints/numGames).setScale(5, RoundingMode.HALF_UP);
47 | String sql = "INSERT INTO " + /*SCHEMA_NAME + "." +*/ TABLE_NAME + "(" +
48 | "YEAR, TEAM_NAME, NUM_GAMES, NUM_OPPONENT_POINTS, AVG_OPPONENT_POINTS_PER_GAME)"
49 | + "VALUES(" +
50 | Integer.valueOf(year) + "," +
51 | "'" + teamName + "'," +
52 | numGames + "," +
53 | numPoints + "," +
54 | AvergePointsPerGame.doubleValue() +
55 | ");" + "\n"
56 | ;
57 | sb.append(sql);
58 | incrementNumberOfRowsProcessed();
59 | }
60 | return sb.toString();
61 | }
62 |
63 | }
64 |
--------------------------------------------------------------------------------
/NcaaMarchMadness/src/main/java/com/makotojava/ncaabb/sqlgenerator/StealsPerGame.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2017 Makoto Consulting Group, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.makotojava.ncaabb.sqlgenerator;
17 |
18 | import java.math.BigDecimal;
19 | import java.math.RoundingMode;
20 | import java.util.List;
21 |
22 | import org.apache.log4j.Logger;
23 |
24 | public class StealsPerGame extends AbstractStrategy {
25 |
26 | private static final Logger LOG = Logger.getLogger(StealsPerGame.class);
27 |
28 | public static final String TABLE_NAME = "steals_per_game";
29 |
30 | public final static String STATCAT_STEALS_PER_GAME = "Steals Per Game";
31 |
32 | public StealsPerGame() {
33 | super(StealsPerGame.STATCAT_STEALS_PER_GAME);
34 | }
35 |
36 | @Override
37 | public String generateSql(String year, List data) {
38 | StringBuilder sb = new StringBuilder();
39 | LOG.debug("Generating SQL for stat cat => " + getStrategyName() + " and year => " + year);
40 | LOG.debug("There are " + data.size() + " lines of data to be processed...");
41 | for (String[] line : data) {
42 | String teamName = line[1];
43 | int numGames = Integer.valueOf(line[2]);
44 | // Ignore W-L (don't care)
45 | int numSteals = Integer.valueOf(line[4]);
46 | // Compute SPG
47 | BigDecimal stealsPerGame = BigDecimal.valueOf((double) numSteals / numGames).setScale(5, RoundingMode.HALF_UP);
48 | String sql = "INSERT INTO " + /* SCHEMA_NAME + "." + */TABLE_NAME + "(" +
49 | "YEAR, TEAM_NAME, NUM_GAMES, NUM_STEALS, STEALS_PER_GAME"
50 | + ")"
51 | + "VALUES(" +
52 | Integer.valueOf(year) + "," +
53 | "'" + teamName + "'," +
54 | numGames + "," +
55 | numSteals + "," +
56 | stealsPerGame.doubleValue() +
57 | ");" + "\n";
58 | sb.append(sql);
59 | incrementNumberOfRowsProcessed();
60 | }
61 | return sb.toString();
62 | }
63 |
64 | }
65 |
--------------------------------------------------------------------------------
/NcaaMarchMadness/src/main/java/com/makotojava/ncaabb/sqlgenerator/WonLostPercentageStrategy.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2017 Makoto Consulting Group, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.makotojava.ncaabb.sqlgenerator;
17 |
18 | import java.math.BigDecimal;
19 | import java.math.RoundingMode;
20 | import java.util.List;
21 |
22 | import org.apache.log4j.Logger;
23 |
24 | public class WonLostPercentageStrategy extends AbstractStrategy {
25 |
26 | private static final Logger LOG = Logger.getLogger(WonLostPercentageStrategy.class);
27 |
28 | public static final String TABLE_NAME = "won_lost_percentage";
29 |
30 | public final static String STATCAT_WON_LOST_PERCENTAGE = "Won-Lost Percentage";
31 |
32 | public WonLostPercentageStrategy() {
33 | super(WonLostPercentageStrategy.STATCAT_WON_LOST_PERCENTAGE);
34 | }
35 |
36 | @Override
37 | public String generateSql(String year, List data) {
38 | //
39 | StringBuilder sb = new StringBuilder();
40 | LOG.debug("Generating SQL for stat cat => " + getStrategyName() + " and year => " + year);
41 | LOG.debug("There are " + data.size() + " lines of data to be processed...");
42 | for (String[] line : data) {
43 | int numWins = Integer.valueOf(line[2]);
44 | int numLosses = Integer.valueOf(line[3]);
45 | int numGames = numWins + numLosses;
46 | BigDecimal winLossPercentage = BigDecimal.valueOf((double)numWins/numGames).setScale(5, RoundingMode.HALF_UP);
47 | String sql = "INSERT INTO " + /*SCHEMA_NAME + "." +*/ TABLE_NAME + "(" +
48 | "YEAR, TEAM_NAME, NUM_WINS, NUM_LOSSES, WIN_PERCENTAGE)"
49 | + "VALUES(" +
50 | Integer.valueOf(year) + "," +
51 | "'" + line[1] + "'," +
52 | numWins + "," +
53 | numLosses + "," +
54 | winLossPercentage.doubleValue() +
55 | ");" + "\n"
56 | ;
57 | sb.append(sql);
58 | incrementNumberOfRowsProcessed();
59 | }
60 | return sb.toString();
61 | }
62 |
63 | }
--------------------------------------------------------------------------------
/NcaaMarchMadness/src/main/java/com/makotojava/ncaabb/sqlgenerator/TurnoversPerGame.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2017 Makoto Consulting Group, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.makotojava.ncaabb.sqlgenerator;
17 |
18 | import java.math.BigDecimal;
19 | import java.math.RoundingMode;
20 | import java.util.List;
21 |
22 | import org.apache.log4j.Logger;
23 |
24 | public class TurnoversPerGame extends AbstractStrategy {
25 |
26 | private static final Logger LOG = Logger.getLogger(TurnoversPerGame.class);
27 |
28 | public static final String TABLE_NAME = "turnovers_per_game";
29 |
30 | public final static String STATCAT_TURNOVERS_PER_GAME = "Turnovers Per Game";
31 |
32 | public TurnoversPerGame() {
33 | super(TurnoversPerGame.STATCAT_TURNOVERS_PER_GAME);
34 | }
35 |
36 | @Override
37 | public String generateSql(String year, List data) {
38 | StringBuilder sb = new StringBuilder();
39 | LOG.debug("Generating SQL for stat cat => " + getStrategyName() + " and year => " + year);
40 | LOG.debug("There are " + data.size() + " lines of data to be processed...");
41 | for (String[] line : data) {
42 | String teamName = line[1];
43 | int numGames = Integer.valueOf(line[2]);
44 | // Ignore W-L (don't care)
45 | int numTurnovers = Integer.valueOf(line[4]);
46 | // Compute TOPG
47 | BigDecimal turnoversPerGame = BigDecimal.valueOf((double) numTurnovers / numGames).setScale(5, RoundingMode.HALF_UP);
48 | String sql = "INSERT INTO " + /* SCHEMA_NAME + "." + */TABLE_NAME + "(" +
49 | "YEAR, TEAM_NAME, NUM_GAMES, NUM_TURNOVERS, TURNOVERS_PER_GAME"
50 | + ")"
51 | + "VALUES(" +
52 | Integer.valueOf(year) + "," +
53 | "'" + teamName + "'," +
54 | numGames + "," +
55 | numTurnovers + "," +
56 | turnoversPerGame.doubleValue() +
57 | ");" + "\n";
58 | sb.append(sql);
59 | incrementNumberOfRowsProcessed();
60 | }
61 | return sb.toString();
62 | }
63 |
64 | }
65 |
--------------------------------------------------------------------------------
/NcaaMarchMadness/src/main/java/com/makotojava/ncaabb/sqlgenerator/BlockedShotsPerGame.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2017 Makoto Consulting Group, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.makotojava.ncaabb.sqlgenerator;
17 |
18 | import java.math.BigDecimal;
19 | import java.math.RoundingMode;
20 | import java.util.List;
21 |
22 | import org.apache.log4j.Logger;
23 |
24 | public class BlockedShotsPerGame extends AbstractStrategy {
25 |
26 | private static final Logger LOG = Logger.getLogger(BlockedShotsPerGame.class);
27 |
28 | public static final String TABLE_NAME = "blocked_shots_per_game";
29 |
30 | public final static String STATCAT_BLOCKED_SHOTS_PER_GAME = "Blocked Shots Per Game";
31 |
32 | public BlockedShotsPerGame() {
33 | super(BlockedShotsPerGame.STATCAT_BLOCKED_SHOTS_PER_GAME);
34 | }
35 |
36 | @Override
37 | public String generateSql(String year, List data) {
38 | StringBuilder sb = new StringBuilder();
39 | LOG.debug("Generating SQL for stat cat => " + getStrategyName() + " and year => " + year);
40 | LOG.debug("There are " + data.size() + " lines of data to be processed...");
41 | for (String[] line : data) {
42 | String teamName = line[1];
43 | int numGames = Integer.valueOf(line[2]);
44 | // Ignore W-L (don't care)
45 | int numBlocks = Integer.valueOf(line[4]);
46 | // Compute BPG
47 | BigDecimal blocksPerGame = BigDecimal.valueOf((double) numBlocks / numGames).setScale(5, RoundingMode.HALF_UP);
48 | String sql = "INSERT INTO " + /* SCHEMA_NAME + "." + */TABLE_NAME + "(" +
49 | "YEAR, TEAM_NAME, NUM_GAMES, NUM_BLOCKS, BLOCKS_PER_GAME"
50 | + ")"
51 | + "VALUES(" +
52 | Integer.valueOf(year) + "," +
53 | "'" + teamName + "'," +
54 | numGames + "," +
55 | numBlocks + "," +
56 | blocksPerGame.doubleValue() +
57 | ");" + "\n";
58 | sb.append(sql);
59 | incrementNumberOfRowsProcessed();
60 | }
61 | return sb.toString();
62 | }
63 |
64 | }
65 |
--------------------------------------------------------------------------------
/NcaaMarchMadness/src/main/java/com/makotojava/ncaabb/sqlgenerator/ThreePointFieldGoalsPerGame.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2017 Makoto Consulting Group, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.makotojava.ncaabb.sqlgenerator;
17 |
18 | import java.math.BigDecimal;
19 | import java.math.RoundingMode;
20 | import java.util.List;
21 |
22 | import org.apache.log4j.Logger;
23 |
24 | public class ThreePointFieldGoalsPerGame extends AbstractStrategy {
25 |
26 | private static final Logger LOG = Logger.getLogger(ThreePointFieldGoalsPerGame.class);
27 |
28 | public static final String TABLE_NAME = "three_point_field_goals_per_game";
29 |
30 | public final static String STATCAT_THREE_POINT_FIELD_GOALS_PER_GAME = "Three-Point Field Goals Per Game";
31 |
32 | public ThreePointFieldGoalsPerGame() {
33 | super(ThreePointFieldGoalsPerGame.STATCAT_THREE_POINT_FIELD_GOALS_PER_GAME);
34 | }
35 |
36 | @Override
37 | public String generateSql(String year, List data) {
38 | //
39 | StringBuilder sb = new StringBuilder();
40 | LOG.debug("Generating SQL for stat cat => " + getStrategyName() + " and year => " + year);
41 | LOG.debug("There are " + data.size() + " lines of data to be processed...");
42 | for (String[] line : data) {
43 | String teamName = line[1];
44 | int numGames = Integer.valueOf(line[2]);
45 | int numMade = Integer.valueOf(line[4]);
46 | BigDecimal pgPct = BigDecimal.valueOf((double)numMade/numGames).setScale(5, RoundingMode.HALF_UP);
47 | String sql = "INSERT INTO " + /*SCHEMA_NAME + "." +*/ TABLE_NAME + "(" +
48 | "YEAR, TEAM_NAME, NUM_GAMES, NUM_3P_MADE, NUM_3P_PER_GAME)"
49 | + "VALUES(" +
50 | Integer.valueOf(year) + "," +
51 | "'" + teamName + "'," +
52 | numGames + "," +
53 | numMade + "," +
54 | pgPct.doubleValue() +
55 | ");" + "\n"
56 | ;
57 | sb.append(sql);
58 | incrementNumberOfRowsProcessed();
59 | }
60 | return sb.toString();
61 | }
62 |
63 | }
64 |
--------------------------------------------------------------------------------
/NcaaMarchMadness/src/main/java/com/makotojava/ncaabb/sqlgenerator/AssistsPerGame.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2017 Makoto Consulting Group, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.makotojava.ncaabb.sqlgenerator;
17 |
18 | import java.math.BigDecimal;
19 | import java.math.RoundingMode;
20 | import java.util.List;
21 |
22 | import org.apache.log4j.Logger;
23 |
24 | public class AssistsPerGame extends AbstractStrategy {
25 |
26 | private static final Logger LOG = Logger.getLogger(AssistsPerGame.class);
27 |
28 | public static final String TABLE_NAME = "assists_per_game";
29 |
30 | public final static String STATCAT_ASSISTS_PER_GAME = "Assists Per Game";
31 |
32 | public AssistsPerGame() {
33 | super(AssistsPerGame.STATCAT_ASSISTS_PER_GAME);
34 | }
35 |
36 | @Override
37 | public String generateSql(String year, List data) {
38 | StringBuilder sb = new StringBuilder();
39 | LOG.debug("Generating SQL for stat cat => " + getStrategyName() + " and year => " + year);
40 | LOG.debug("There are " + data.size() + " lines of data to be processed...");
41 | for (String[] line : data) {
42 | String teamName = line[1];
43 | int numGames = Integer.valueOf(line[2]);
44 | // Ignore W-L (don't care)
45 | int numAssists = Integer.valueOf(line[4]);
46 | // Ignore APG (will calculate ourselves to a greater level of precision)
47 | BigDecimal assistsPerGame = BigDecimal.valueOf((double)numAssists/numGames).setScale(5, RoundingMode.HALF_UP);
48 | String sql = "INSERT INTO " + /*SCHEMA_NAME + "." + */TABLE_NAME + "(" +
49 | "YEAR, TEAM_NAME, NUM_GAMES, NUM_ASSISTS, ASSISTS_PER_GAME"
50 | + ")"
51 | + "VALUES(" +
52 | Integer.valueOf(year) + "," +
53 | "'" + teamName + "'," +
54 | numGames + "," +
55 | numAssists + "," +
56 | assistsPerGame.doubleValue() +
57 | ");" + "\n"
58 | ;
59 | sb.append(sql);
60 | incrementNumberOfRowsProcessed();
61 | }
62 | return sb.toString();
63 | }
64 |
65 | }
66 |
--------------------------------------------------------------------------------
/NcaaMarchMadness/src/main/java/com/makotojava/ncaabb/dao/SeasonDataDao.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2017 Makoto Consulting Group, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.makotojava.ncaabb.dao;
17 |
18 | import java.util.List;
19 |
20 | import org.springframework.stereotype.Component;
21 |
22 | import com.makotojava.ncaabb.model.SeasonData;
23 |
24 | /**
25 | * Data Access Object interface for SeasonData model data.
26 | *
27 | * @author J Steven Perry
28 | *
29 | */
30 | @Component
31 | public interface SeasonDataDao {
32 |
33 | /**
34 | * Fetch all {@link SeasonData} objects by the specified year
35 | * and return a List. The List
36 | * will be empty if no {@link SeasonData} objects could be found for
37 | * the specified year (which probably means you forgot to load the
38 | * data into the DB, shame, shame, shame).
39 | *
40 | * @param year
41 | * The year for which {@link SeasonData} objects are to be
42 | * fetched.
43 | * @return List - the List of
44 | * {@link SeasonData} objects if they could be located, or an empty list
45 | * if not.
46 | */
47 | public List fetchAllByYear(Integer year);
48 |
49 | /**
50 | * Fetch the {@link SeasonData} object associated with the specified
51 | * year and teamName. This combination is
52 | * guaranteed to be unique in the system.
53 | *
54 | * @param year
55 | * The year for which the {@link SeasonData} object is to be
56 | * fetched.
57 | * @param teamName
58 | * The team name for which the {@link SeasonData} object
59 | * is to be fetched.
60 | * @return {@link SeasonData} - The {@link SeasonData} object associated
61 | * with the unique combination of year and teamName
62 | * or null if no such object could be found.
63 | */
64 | public SeasonData fetchByYearAndTeamName(Integer year, String teamName);
65 |
66 | }
67 |
--------------------------------------------------------------------------------
/NcaaMarchMadness/src/main/java/com/makotojava/ncaabb/sqlgenerator/AssistTurnoverRatio.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2017 Makoto Consulting Group, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.makotojava.ncaabb.sqlgenerator;
17 |
18 | import java.math.BigDecimal;
19 | import java.math.RoundingMode;
20 | import java.util.List;
21 |
22 | import org.apache.log4j.Logger;
23 |
24 | public class AssistTurnoverRatio extends AbstractStrategy {
25 |
26 | private static final Logger LOG = Logger.getLogger(AssistTurnoverRatio.class);
27 |
28 | public static final String TABLE_NAME = "assist_turnover_ratio";
29 |
30 | public final static String STATCAT_ASSIST_TURNOVER_RATIO = "Assist Turnover Ratio";
31 |
32 | public AssistTurnoverRatio() {
33 | super(AssistTurnoverRatio.STATCAT_ASSIST_TURNOVER_RATIO);
34 | }
35 |
36 | @Override
37 | public String generateSql(String year, List data) {
38 | StringBuilder sb = new StringBuilder();
39 | LOG.debug("Generating SQL for stat cat => " + getStrategyName() + " and year => " + year);
40 | LOG.debug("There are " + data.size() + " lines of data to be processed...");
41 | for (String[] line : data) {
42 | String teamName = line[1];
43 | int numGames = Integer.valueOf(line[2]);
44 | // Ignore W-L (don't care)
45 | int numAssists = Integer.valueOf(line[4]);
46 | int numTurnovers = Integer.valueOf(line[5]);
47 | // Compute ATO
48 | BigDecimal atoRatio = BigDecimal.valueOf((double) numAssists / numTurnovers).setScale(5, RoundingMode.HALF_UP);
49 | String sql = "INSERT INTO " + /* SCHEMA_NAME + "." + */TABLE_NAME + "(" +
50 | "YEAR, TEAM_NAME, NUM_GAMES, NUM_ASSISTS, NUM_TURNOVERS, ATO_RATIO"
51 | + ")"
52 | + "VALUES(" +
53 | Integer.valueOf(year) + "," +
54 | "'" + teamName + "'," +
55 | numGames + "," +
56 | numAssists + "," +
57 | numTurnovers + "," +
58 | atoRatio.doubleValue() +
59 | ");" + "\n";
60 | sb.append(sql);
61 | incrementNumberOfRowsProcessed();
62 | }
63 | return sb.toString();
64 | }
65 |
66 | }
67 |
--------------------------------------------------------------------------------
/NcaaMarchMadness/src/main/script/run-data-creator.sh:
--------------------------------------------------------------------------------
1 | #!
2 | #
3 | # Script to run the DataCreator program.
4 | #
5 | # Set DEBUG to something other than true to turn it off
6 | DEBUG=true
7 |
8 | function usage {
9 | echo "Usage: $0 year [year2 ... yearN]"
10 | echo "Description: creates training data for the specified year(s)"
11 | echo "Where:"
12 | echo -e "\tyear is the first (and possibly only) year for which training data is to be created."
13 | echo -e "\tyear2 (optional) is the second year (if specified) for which training data is to be created."
14 | echo -e "\tyearN (optional) is the Nth year (if specified) for which training data is to be created."
15 | echo "Examples:"
16 | echo "Create training data for 2010:"
17 | echo -e "\t$0 2010"
18 | echo "Create training data for 2011 and 2013"
19 | echo -e "\t$0 2011 2013"
20 | echo
21 | }
22 |
23 | # Process number of arguments
24 | NUMARGS=$#
25 | if [ "$DEBUG" == "true" ]; then echo -e \\n"Number of arguments: $NUMARGS"; fi
26 | if [ "$NUMARGS" -eq 0 ]; then
27 | usage
28 | exit 1
29 | fi
30 | if [ "$DEBUG" == "true" ]; then echo "Script arguments: $@"; fi
31 |
32 | # Below is an example that works on my Mac.
33 | # Change this to match your source location.
34 | ROOT_DIR=/Users/sperry/home/development/projects/developerWorks/NcaaMarchMadness
35 |
36 | # Make sure ROOT_DIR is set or bail out
37 | if [ -z "$ROOT_DIR" ]
38 | then
39 | echo "ROOT_DIR is not set! This variable should be set to the source root of your project."
40 | echo "Make sure that you run a Maven build to create the necessary class files"
41 | echo "and library dependencies"
42 | exit 1
43 | fi
44 |
45 | if [ "$DEBUG" == "true" ]; then echo "ROOT_DIR = ${ROOT_DIR}"; fi
46 |
47 | # Set the lib directory as a convenience
48 | LIB_DIR=$ROOT_DIR/target/lib
49 |
50 | SPRING_FRAMEWORK_VERSION=4.3.6.RELEASE
51 |
52 | # Set the CLASSPATH to use.
53 | CP=\
54 | $LIB_DIR/neuroph-2.94.jar:\
55 | $LIB_DIR/postgresql-9.1-901-1.jdbc4.jar:\
56 | $LIB_DIR/commons-lang3-3.4.jar:\
57 | $LIB_DIR/spring-context-$SPRING_FRAMEWORK_VERSION.jar:\
58 | $LIB_DIR/spring-core-$SPRING_FRAMEWORK_VERSION.jar:\
59 | $LIB_DIR/spring-beans-$SPRING_FRAMEWORK_VERSION.jar:\
60 | $LIB_DIR/spring-aop-$SPRING_FRAMEWORK_VERSION.jar:\
61 | $LIB_DIR/spring-expression-$SPRING_FRAMEWORK_VERSION.jar:\
62 | $LIB_DIR/spring-jdbc-$SPRING_FRAMEWORK_VERSION.jar:\
63 | $LIB_DIR/spring-tx-$SPRING_FRAMEWORK_VERSION.jar:\
64 | $LIB_DIR/log4j-1.2.17.jar:\
65 | $LIB_DIR/jcl-over-slf4j-1.7.22.jar:\
66 | $LIB_DIR/slf4j-api-1.7.22.jar
67 |
68 | if [ "$DEBUG" == "true" ]; then echo "CLASSPATH = $CP"; fi
69 |
70 | # Fire up the program
71 | java -cp $CP:$ROOT_DIR/target/classes com.makotojava.ncaabb.generation.DataCreator $@
--------------------------------------------------------------------------------
/NcaaMarchMadness/src/main/java/com/makotojava/ncaabb/sqlgenerator/PersonalFoulsPerGame.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2017 Makoto Consulting Group, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.makotojava.ncaabb.sqlgenerator;
17 |
18 | import java.math.BigDecimal;
19 | import java.math.RoundingMode;
20 | import java.util.List;
21 |
22 | import org.apache.log4j.Logger;
23 |
24 | public class PersonalFoulsPerGame extends AbstractStrategy {
25 |
26 | private static final Logger LOG = Logger.getLogger(PersonalFoulsPerGame.class);
27 |
28 | public static final String TABLE_NAME = "personal_fouls_per_game";
29 |
30 | public final static String STATCAT_PERSONAL_FOULS_PER_GAME = "Personal Fouls Per Game";
31 |
32 | public PersonalFoulsPerGame() {
33 | super(PersonalFoulsPerGame.STATCAT_PERSONAL_FOULS_PER_GAME);
34 | }
35 |
36 | @Override
37 | public String generateSql(String year, List data) {
38 | StringBuilder sb = new StringBuilder();
39 | LOG.debug("Generating SQL for stat cat => " + getStrategyName() + " and year => " + year);
40 | LOG.debug("There are " + data.size() + " lines of data to be processed...");
41 | for (String[] line : data) {
42 | String teamName = line[1];
43 | int numGames = Integer.valueOf(line[2]);
44 | // Ignore W-L (don't care)
45 | int numFouls = Integer.valueOf(line[4]);
46 | // Ignore PFPG (will calculate ourselves to a greater level of precision)
47 | int numDq = Integer.valueOf(line[6]);
48 | // Compute PFPG
49 | BigDecimal foulsPerGame = BigDecimal.valueOf((double)numFouls/numGames).setScale(5, RoundingMode.HALF_UP);
50 | String sql = "INSERT INTO " + /*SCHEMA_NAME + "." + */TABLE_NAME + "(" +
51 | "YEAR, TEAM_NAME, NUM_GAMES, NUM_FOULS, FOULS_PER_GAME, NUM_DQ"
52 | + ")"
53 | + "VALUES(" +
54 | Integer.valueOf(year) + "," +
55 | "'" + teamName + "'," +
56 | numGames + "," +
57 | numFouls + "," +
58 | foulsPerGame.doubleValue() + "," +
59 | numDq +
60 | ");" + "\n"
61 | ;
62 | sb.append(sql);
63 | incrementNumberOfRowsProcessed();
64 | }
65 | return sb.toString();
66 | }
67 |
68 | }
69 |
--------------------------------------------------------------------------------
/NcaaMarchMadness/src/main/script/run-sql-generator.sh:
--------------------------------------------------------------------------------
1 | #!
2 | #
3 | # Script to run the SqlGenerator program.
4 | #
5 | # Set DEBUG to something other than true to turn it off
6 | DEBUG=true
7 |
8 | function usage {
9 | echo "Usage: $0 season_data_file"
10 | echo "Description: creates SQL load scripts for the specified NCAA Basketball season data file"
11 | echo "Where:"
12 | echo -e "\tseason_data_file is the fully qualified path to the CSV file "
13 | echo -e "\tcontaining the raw data from which SQL load scripts are to be created."
14 | echo "Examples:"
15 | echo "Create SQL load scripts from /Users/sperry/l/MarchMadness/data/2016/rankings.csv"
16 | echo -e "\t$0 /Users/sperry/l/MarchMadness/data/2016/rankings.csv"
17 | echo "Create SQL load scripts from /Users/sperry/l/MarchMadness/data/2015/rankings-2015.csv"
18 | echo -e "\t$0 /Users/sperry/l/MarchMadness/data/2015/rankings-2015.csv"
19 | echo
20 | }
21 |
22 | # Process number of arguments
23 | NUMARGS=$#
24 | if [ "$DEBUG" == "true" ]; then echo -e \\n"Number of arguments: $NUMARGS"; fi
25 | if [ "$NUMARGS" -eq 0 ]; then
26 | usage
27 | exit 1
28 | fi
29 | if [ "$DEBUG" == "true" ]; then echo "Script arguments: $@"; fi
30 |
31 | # Below is an example that works on my Mac.
32 | # Change this to match your source location.
33 | ROOT_DIR=/Users/sperry/home/development/projects/developerWorks/NcaaMarchMadness
34 |
35 | # Make sure ROOT_DIR is set or bail out
36 | if [ -z "$ROOT_DIR" ]
37 | then
38 | echo "ROOT_DIR is not set! This variable should be set to the source root of your project."
39 | echo "Make sure that you run a Maven build to create the necessary class files"
40 | echo "and library dependencies"
41 | exit 1
42 | fi
43 |
44 | if [ "$DEBUG" == "true" ]; then echo "ROOT_DIR = ${ROOT_DIR}"; fi
45 |
46 | # Set the lib directory as a convenience
47 | LIB_DIR=$ROOT_DIR/target/lib
48 |
49 | SPRING_FRAMEWORK_VERSION=4.3.6.RELEASE
50 |
51 | # Set the CLASSPATH to use.
52 | CP=\
53 | $LIB_DIR/neuroph-2.94.jar:\
54 | $LIB_DIR/postgresql-9.1-901-1.jdbc4.jar:\
55 | $LIB_DIR/commons-lang3-3.4.jar:\
56 | $LIB_DIR/spring-context-$SPRING_FRAMEWORK_VERSION.jar:\
57 | $LIB_DIR/spring-core-$SPRING_FRAMEWORK_VERSION.jar:\
58 | $LIB_DIR/spring-beans-$SPRING_FRAMEWORK_VERSION.jar:\
59 | $LIB_DIR/spring-aop-$SPRING_FRAMEWORK_VERSION.jar:\
60 | $LIB_DIR/spring-expression-$SPRING_FRAMEWORK_VERSION.jar:\
61 | $LIB_DIR/spring-jdbc-$SPRING_FRAMEWORK_VERSION.jar:\
62 | $LIB_DIR/spring-tx-$SPRING_FRAMEWORK_VERSION.jar:\
63 | $LIB_DIR/log4j-1.2.17.jar:\
64 | $LIB_DIR/jcl-over-slf4j-1.7.22.jar:\
65 | $LIB_DIR/slf4j-api-1.7.22.jar:\
66 | $LIB_DIR/opencsv-3.6.jar
67 |
68 | if [ "$DEBUG" == "true" ]; then echo "CLASSPATH = $CP"; fi
69 |
70 | # Fire up the program
71 | java -cp $CP:$ROOT_DIR/target/classes com.makotojava.ncaabb.sqlgenerator.SqlGenerator $@
--------------------------------------------------------------------------------
/NcaaMarchMadness/src/main/script/run-tournament_participant-sql-generator.sh:
--------------------------------------------------------------------------------
1 | #!
2 | #
3 | # Script to run the SqlGenerator program.
4 | #
5 | # Set DEBUG to something other than true to turn it off
6 | DEBUG=true
7 |
8 | function usage {
9 | echo "Usage: $0 tournament_participants_file year"
10 | echo "Description: creates SQL load script for the specified NCAA Basketball tournament participants"
11 | echo " and writes it out to the same location for the specified year."
12 | echo "Where:"
13 | echo -e "\ttournament_participants_file is the fully qualified path to the file "
14 | echo -e "\tcontaining the raw data from which SQL load scripts are to be created."
15 | echo -e "\tyear is the tournament year."
16 | echo
17 | echo "Examples:"
18 | echo "Create SQL load scripts from /Users/sperry/developerWorks/NcaaMarchMadness/src/main/data/tourney_teams_file_2009.txt"
19 | echo " for tournament year 2009"
20 | echo -e "\t$0 /Users/sperry/l/MarchMadness/data/tourney_teams_file_2009.txt 2009"
21 | echo
22 | }
23 |
24 | # Process number of arguments
25 | NUMARGS=$#
26 | if [ "$DEBUG" == "true" ]; then echo -e \\n"Number of arguments: $NUMARGS"; fi
27 | if [ "$NUMARGS" -eq 0 ]; then
28 | usage
29 | exit 1
30 | fi
31 | if [ "$DEBUG" == "true" ]; then echo "Script arguments: $@"; fi
32 |
33 | # Below is an example that works on my Mac.
34 | # Change this to match your source location.
35 | ROOT_DIR=/Users/sperry/home/development/projects/developerWorks/NcaaMarchMadness
36 |
37 | # Make sure ROOT_DIR is set or bail out
38 | if [ -z "$ROOT_DIR" ]
39 | then
40 | echo "ROOT_DIR is not set! This variable should be set to the source root of your project."
41 | echo "Make sure that you run a Maven build to create the necessary class files"
42 | echo "and library dependencies"
43 | exit 1
44 | fi
45 |
46 | if [ "$DEBUG" == "true" ]; then echo "ROOT_DIR = ${ROOT_DIR}"; fi
47 |
48 | # Set the lib directory as a convenience
49 | LIB_DIR=$ROOT_DIR/target/lib
50 |
51 | SPRING_FRAMEWORK_VERSION=4.3.6.RELEASE
52 |
53 | # Set the CLASSPATH to use.
54 | CP=\
55 | $LIB_DIR/neuroph-2.94.jar:\
56 | $LIB_DIR/postgresql-9.1-901-1.jdbc4.jar:\
57 | $LIB_DIR/commons-lang3-3.4.jar:\
58 | $LIB_DIR/spring-context-$SPRING_FRAMEWORK_VERSION.jar:\
59 | $LIB_DIR/spring-core-$SPRING_FRAMEWORK_VERSION.jar:\
60 | $LIB_DIR/spring-beans-$SPRING_FRAMEWORK_VERSION.jar:\
61 | $LIB_DIR/spring-aop-$SPRING_FRAMEWORK_VERSION.jar:\
62 | $LIB_DIR/spring-expression-$SPRING_FRAMEWORK_VERSION.jar:\
63 | $LIB_DIR/spring-jdbc-$SPRING_FRAMEWORK_VERSION.jar:\
64 | $LIB_DIR/spring-tx-$SPRING_FRAMEWORK_VERSION.jar:\
65 | $LIB_DIR/log4j-1.2.17.jar:\
66 | $LIB_DIR/jcl-over-slf4j-1.7.22.jar:\
67 | $LIB_DIR/slf4j-api-1.7.22.jar:\
68 | $LIB_DIR/opencsv-3.6.jar
69 |
70 | if [ "$DEBUG" == "true" ]; then echo "CLASSPATH = $CP"; fi
71 |
72 | # Fire up the program
73 | java -cp $CP:$ROOT_DIR/target/classes com.makotojava.ncaabb.sqlgenerator.TournamentParticipantSqlGenerator $@
--------------------------------------------------------------------------------
/NcaaMarchMadness/src/main/java/com/makotojava/ncaabb/util/StatsUtils.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2017 Makoto Consulting Group, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.makotojava.ncaabb.util;
17 |
18 | import java.math.BigDecimal;
19 | import java.math.RoundingMode;
20 |
21 | import org.apache.log4j.Logger;
22 |
23 | public class StatsUtils {
24 |
25 | private static final Logger log = Logger.getLogger(StatsUtils.class);
26 |
27 | public static final int SCALE = 5;
28 |
29 | public static final double MIN_ALLOWABLE_VALUE = 0.00001;
30 |
31 | public static final double MAX_ALLOWABLE_VALUE = 0.99999;
32 |
33 | private StatsUtils() {
34 | // Can't touch this
35 | }
36 |
37 | public static BigDecimal normalize(BigDecimal value, BigDecimal minValue, BigDecimal maxValue) {
38 | BigDecimal ret;
39 | //
40 | // If the value is null, then set it to the min (nulls cause the program to crash)
41 | if (value == null) {
42 | value = minValue;
43 | }
44 | //
45 | ret = value.subtract(minValue).divide(maxValue.subtract(minValue), RoundingMode.HALF_UP);
46 | if (ret.doubleValue() >= 1.0) {
47 | ret = BigDecimal.valueOf(MAX_ALLOWABLE_VALUE);
48 | } else if (ret.doubleValue() <= 0.0) {
49 | ret = BigDecimal.valueOf(MIN_ALLOWABLE_VALUE);
50 | }
51 | //
52 | log.trace("Normalized value: " + ret + " = " + "(" + value + " - " + minValue + ") / (" + maxValue + " - " + minValue + ")");
53 | return ret;
54 | }
55 |
56 | /**
57 | * Some values (Opponent defensive values, for example) are more meaningful the lower
58 | * they are, so we need to invert those values to put them on the same footing as the
59 | * values where bigger is better, so that bigger-is-better works for all numbers
60 | *
61 | * @param value
62 | * @param minValue
63 | * @param maxValue
64 | * @return
65 | */
66 | public static BigDecimal normalizeInverted(BigDecimal value, BigDecimal minValue, BigDecimal maxValue) {
67 | BigDecimal ret;
68 | BigDecimal normalizedValue = normalize(value, minValue, maxValue);
69 | BigDecimal one = BigDecimal.ONE.setScale(normalizedValue.scale(), RoundingMode.HALF_UP);
70 | // Return 1 - normalizedValue
71 | ret = one.subtract(normalizedValue);
72 | log.trace("Returning Inverted value: " + ret);
73 | return ret;
74 | }
75 |
76 | }
77 |
--------------------------------------------------------------------------------
/NcaaMarchMadness/src/main/java/com/makotojava/ncaabb/sqlgenerator/ScoringMargin.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2017 Makoto Consulting Group, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.makotojava.ncaabb.sqlgenerator;
17 |
18 | import java.math.BigDecimal;
19 | import java.math.RoundingMode;
20 | import java.util.List;
21 |
22 | import org.apache.log4j.Logger;
23 |
24 | public class ScoringMargin extends AbstractStrategy {
25 |
26 | private static final Logger LOG = Logger.getLogger(ScoringMargin.class);
27 |
28 | public static final String TABLE_NAME = "scoring_margin";
29 |
30 | public final static String STATCAT_SCORING_MARGIN = "Scoring Margin";
31 |
32 | public ScoringMargin() {
33 | super(ScoringMargin.STATCAT_SCORING_MARGIN);
34 | }
35 |
36 | @Override
37 | public String generateSql(String year, List data) {
38 | //
39 | StringBuilder sb = new StringBuilder();
40 | LOG.debug("Generating SQL for stat cat => " + getStrategyName() + " and year => " + year);
41 | LOG.debug("There are " + data.size() + " lines of data to be processed...");
42 | for (String[] line : data) {
43 | String teamName = line[1];
44 | int numGames = Integer.valueOf(line[2]);
45 | int numPoints = Integer.valueOf(line[4]);
46 | int numOppPoints = Integer.valueOf(line[6]);
47 | BigDecimal avgPpg = BigDecimal.valueOf((double)numPoints/numGames).setScale(5, RoundingMode.HALF_UP);
48 | BigDecimal avgOppPpg = BigDecimal.valueOf((double)numOppPoints/numGames).setScale(5, RoundingMode.HALF_UP);
49 | BigDecimal scoringMarginPerGame = avgPpg.subtract(avgOppPpg).setScale(5, RoundingMode.HALF_UP);
50 | int scoringMarginSeason = numPoints - numOppPoints;
51 | String sql = "INSERT INTO " + /*SCHEMA_NAME + "." +*/ TABLE_NAME + "(" +
52 | "YEAR, TEAM_NAME, NUM_GAMES, NUM_POINTS, NUM_OPPONENT_POINTS, SCORING_MARGIN_PER_GAME, SCORING_MARGIN_SEASON)"
53 | + "VALUES(" +
54 | Integer.valueOf(year) + "," +
55 | "'" + teamName + "'," +
56 | numGames + "," +
57 | numPoints + "," +
58 | numOppPoints + "," +
59 | scoringMarginPerGame.doubleValue() + "," +
60 | scoringMarginSeason +
61 | ");" + "\n"
62 | ;
63 | sb.append(sql);
64 | incrementNumberOfRowsProcessed();
65 | }
66 | return sb.toString();
67 | }
68 |
69 | }
70 |
--------------------------------------------------------------------------------
/NcaaMarchMadness/src/main/java/com/makotojava/ncaabb/sqlgenerator/FreeThrowPercentage.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2017 Makoto Consulting Group, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.makotojava.ncaabb.sqlgenerator;
17 |
18 | import java.math.BigDecimal;
19 | import java.math.RoundingMode;
20 | import java.util.List;
21 |
22 | import org.apache.log4j.Logger;
23 |
24 | public class FreeThrowPercentage extends AbstractStrategy {
25 |
26 | private static final Logger LOG = Logger.getLogger(FreeThrowPercentage.class);
27 |
28 | public static final String TABLE_NAME = "free_throw_percentage";
29 |
30 | public final static String STATCAT_FREE_THROW_PERCENTAGE = "Free-Throw Percentage";
31 |
32 | public FreeThrowPercentage() {
33 | super(FreeThrowPercentage.STATCAT_FREE_THROW_PERCENTAGE);
34 | }
35 |
36 | @Override
37 | public String generateSql(String year, List data) {
38 | //
39 | StringBuilder sb = new StringBuilder();
40 | LOG.debug("Generating SQL for stat cat => " + getStrategyName() + " and year => " + year);
41 | LOG.debug("There are " + data.size() + " lines of data to be processed...");
42 | for (String[] line : data) {
43 | String teamName = line[1];
44 | int numGames = Integer.valueOf(line[2]);
45 | int numMade = Integer.valueOf(line[4]);
46 | int numAtt = Integer.valueOf(line[5]);
47 | BigDecimal pgAvg = BigDecimal.valueOf((double)numMade/numGames).setScale(5, RoundingMode.HALF_UP);
48 | BigDecimal pgAttAvg = BigDecimal.valueOf((double)numAtt/numGames).setScale(5, RoundingMode.HALF_UP);
49 | BigDecimal pct = BigDecimal.valueOf((double)numMade/numAtt).setScale(5, RoundingMode.HALF_UP);
50 | String sql = "INSERT INTO " + /*SCHEMA_NAME + "." +*/ TABLE_NAME + "(" +
51 | "YEAR, TEAM_NAME, NUM_GAMES, NUM_FT_MADE, NUM_FT_ATTEMPTS, NUM_FT_PER_GAME, NUM_FT_ATTEMPTS_PER_GAME, FT_PERCENTAGE)"
52 | + "VALUES(" +
53 | Integer.valueOf(year) + "," +
54 | "'" + teamName + "'," +
55 | numGames + "," +
56 | numMade + "," +
57 | numAtt + "," +
58 | pgAvg.doubleValue() + "," +
59 | pgAttAvg.doubleValue() + "," +
60 | pct.doubleValue() +
61 | ");" + "\n"
62 | ;
63 | sb.append(sql);
64 | incrementNumberOfRowsProcessed();
65 | }
66 | return sb.toString();
67 | }
68 |
69 | }
70 |
--------------------------------------------------------------------------------
/NcaaMarchMadness/src/main/java/com/makotojava/ncaabb/sqlgenerator/FieldGoalPercentage.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2017 Makoto Consulting Group, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.makotojava.ncaabb.sqlgenerator;
17 |
18 | import java.math.BigDecimal;
19 | import java.math.RoundingMode;
20 | import java.util.List;
21 |
22 | import org.apache.log4j.Logger;
23 |
24 | public class FieldGoalPercentage extends AbstractStrategy {
25 |
26 | private static final Logger LOG = Logger.getLogger(FieldGoalPercentage.class);
27 |
28 | public static final String TABLE_NAME = "field_goal_percentage";
29 |
30 | public final static String STATCAT_FIELD_GOAL_PERCENTAGE = "Field-Goal Percentage";
31 |
32 | public FieldGoalPercentage() {
33 | super(FieldGoalPercentage.STATCAT_FIELD_GOAL_PERCENTAGE);
34 | }
35 |
36 | @Override
37 | public String generateSql(String year, List data) {
38 | //
39 | StringBuilder sb = new StringBuilder();
40 | LOG.debug("Generating SQL for stat cat => " + getStrategyName() + " and year => " + year);
41 | LOG.debug("There are " + data.size() + " lines of data to be processed...");
42 | for (String[] line : data) {
43 | String teamName = line[1];
44 | int numGames = Integer.valueOf(line[2]);
45 | int numFgMade = Integer.valueOf(line[4]);
46 | BigDecimal numFgPerGame = BigDecimal.valueOf((double)numFgMade/numGames).setScale(5, RoundingMode.HALF_UP);
47 | int numFgAtt = Integer.valueOf(line[5]);
48 | BigDecimal numFgAttPerGame = BigDecimal.valueOf((double)numFgAtt/numGames).setScale(5, RoundingMode.HALF_UP);
49 | BigDecimal fgPct = BigDecimal.valueOf((double)numFgMade/numFgAtt).setScale(5, RoundingMode.HALF_UP);
50 | String sql = "INSERT INTO " + /*SCHEMA_NAME + "." + */TABLE_NAME + "(" +
51 | "YEAR, TEAM_NAME, NUM_GAMES, NUM_FG_MADE, NUM_FG_PER_GAME, NUM_FG_ATTEMPTS, NUM_FG_ATTEMPTS_PER_GAME, FG_PERCENTAGE)"
52 | + "VALUES(" +
53 | Integer.valueOf(year) + "," +
54 | "'" + teamName + "'," +
55 | numGames + "," +
56 | numFgMade + "," +
57 | numFgPerGame.doubleValue() + "," +
58 | numFgAtt + "," +
59 | numFgAttPerGame.doubleValue() + "," +
60 | fgPct.doubleValue() +
61 | ");" + "\n"
62 | ;
63 | sb.append(sql);
64 | incrementNumberOfRowsProcessed();
65 | }
66 | return sb.toString();
67 | }
68 | }
69 |
--------------------------------------------------------------------------------
/NcaaMarchMadness/src/main/java/com/makotojava/ncaabb/sqlgenerator/ThreePointPercentage.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2017 Makoto Consulting Group, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.makotojava.ncaabb.sqlgenerator;
17 |
18 | import java.math.BigDecimal;
19 | import java.math.RoundingMode;
20 | import java.util.List;
21 |
22 | import org.apache.log4j.Logger;
23 |
24 | public class ThreePointPercentage extends AbstractStrategy {
25 |
26 | private static final Logger LOG = Logger.getLogger(ThreePointPercentage.class);
27 |
28 | public static final String TABLE_NAME = "three_point_percentage";
29 |
30 | public final static String STATCAT_THREE_POINT_PERCENTAGE = "Three-Point Field-Goal Percentage";
31 |
32 | public ThreePointPercentage() {
33 | super(ThreePointPercentage.STATCAT_THREE_POINT_PERCENTAGE);
34 | }
35 |
36 | @Override
37 | public String generateSql(String year, List data) {
38 | //
39 | StringBuilder sb = new StringBuilder();
40 | LOG.debug("Generating SQL for stat cat => " + getStrategyName() + " and year => " + year);
41 | LOG.debug("There are " + data.size() + " lines of data to be processed...");
42 | for (String[] line : data) {
43 | String teamName = line[1];
44 | int numGames = Integer.valueOf(line[2]);
45 | int numMade = Integer.valueOf(line[4]);
46 | int numAtt = Integer.valueOf(line[5]);
47 | BigDecimal numMadePerGame = BigDecimal.valueOf((double)numMade/numGames).setScale(5, RoundingMode.HALF_UP);
48 | BigDecimal numAttPerGame = BigDecimal.valueOf((double)numAtt/numGames).setScale(5, RoundingMode.HALF_UP);
49 | BigDecimal pct = BigDecimal.valueOf((double)numMade/numAtt).setScale(5, RoundingMode.HALF_UP);
50 | String sql = "INSERT INTO " + /*SCHEMA_NAME + "." +*/ TABLE_NAME + "(" +
51 | "YEAR, TEAM_NAME, NUM_GAMES, NUM_3P_MADE, NUM_3P_ATTEMPTS, NUM_3P_PER_GAME, NUM_3P_ATTEMPTS_PER_GAME, T3P_PERCENTAGE)"
52 | + "VALUES(" +
53 | Integer.valueOf(year) + "," +
54 | "'" + teamName + "'," +
55 | numGames + "," +
56 | numMade + "," +
57 | numAtt + "," +
58 | numMadePerGame.doubleValue() + "," +
59 | numAttPerGame.doubleValue() + "," +
60 | pct.doubleValue() +
61 | ");" + "\n"
62 | ;
63 | sb.append(sql);
64 | incrementNumberOfRowsProcessed();
65 | }
66 | return sb.toString();
67 | }
68 |
69 | }
70 |
--------------------------------------------------------------------------------
/iot-perishable-network/README.md:
--------------------------------------------------------------------------------
1 | # IoT Perishable Goods Network
2 |
3 | > Example business network that shows growers, shippers and importers defining contracts for the price of perishable goods, based on temperature readings from IoT sensors in the shipping containers.
4 |
5 | The business network defines a contract between growers and importers. The contract stipulates that: On receipt of the shipment the importer pays the grower the unit price x the number of units in the shipment. Shipments that arrive late are free. Shipments that have breached the low temperate threshold have a penalty applied proportional to the magnitude of the breach x a penalty factor. Shipments that have breached the high temperate threshold have a penalty applied proportional to the magnitude of the breach x a penalty factor.
6 |
7 | This business network defines:
8 |
9 | **Participants**
10 | `Grower` `Importer` `Shipper`
11 |
12 | **Assets**
13 | `Contract` `Shipment`
14 |
15 | **Transactions**
16 | `TemperatureReading` `GpsReading` `ShipmentReceived` `SetupDemo`
17 |
18 | **Events**
19 | `TemperatureThresholdEvent` `ShipmentInPortEvent`
20 |
21 | To test this Business Network Definition in the **Test** tab:
22 |
23 | Submit a `SetupDemo` transaction:
24 |
25 | ```
26 | {
27 | "$class": "org.acme.shipping.perishable.SetupDemo"
28 | }
29 | ```
30 |
31 | This transaction populates the Participant Registries with a `Grower`, an `Importer` and a `Shipper`. The Asset Registries will have a `Contract` asset and a `Shipment` asset.
32 |
33 | Submit a `TemperatureReading` transaction:
34 |
35 | ```
36 | {
37 | "$class": "org.acme.shipping.perishable.TemperatureReading",
38 | "centigrade": 8,
39 | "shipment": "resource:org.acme.shipping.perishable.Shipment#SHIP_001"
40 | }
41 | ```
42 |
43 | If the temperature reading falls outside the min/max range of the contract, the price received by the grower will be reduced, and a `TemperatureThresholdEvent` is emitted. You may submit several readings if you wish. Each reading will be aggregated within `SHIP_001` Shipment Asset Registry.
44 |
45 | Submit a `ShipmentReceived` transaction for `SHIP_001` to trigger the payout to the grower, based on the parameters of the `CON_001` contract:
46 |
47 | ```
48 | {
49 | "$class": "org.acme.shipping.perishable.ShipmentReceived",
50 | "shipment": "resource:org.acme.shipping.perishable.Shipment#SHIP_001"
51 | }
52 | ```
53 |
54 | If the date-time of the `ShipmentReceived` transaction is after the `arrivalDateTime` on `CON_001` then the grower will no receive any payment for the shipment.
55 |
56 | Submit a `GpsReading` transaction:
57 |
58 | ```
59 | {
60 | "$class": "org.acme.shipping.perishable.GpsReading",
61 | "readingTime": "120000",
62 | "readingDate": "20171024",
63 | "latitude":"40.6840",
64 | "latitudeDir":"N",
65 | "longitude":"74.0062",
66 | "laongitudeDir":"W",
67 | }
68 | ```
69 |
70 | If the GPS reading indicates the ship's location is the Port of New Jersey/New York (40.6840,-74.0062) then a `ShipmentInPortEvent` is emitted.
71 |
72 | Enjoy!
73 |
--------------------------------------------------------------------------------
/NcaaMarchMadness/src/main/java/com/makotojava/ncaabb/springconfig/ApplicationConfig.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2017 Makoto Consulting Group, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.makotojava.ncaabb.springconfig;
17 |
18 | import javax.sql.DataSource;
19 |
20 | import org.postgresql.ds.PGSimpleDataSource;
21 | import org.springframework.context.annotation.Bean;
22 | import org.springframework.context.annotation.ComponentScan;
23 | import org.springframework.context.annotation.Configuration;
24 | import org.springframework.transaction.annotation.EnableTransactionManagement;
25 |
26 | import com.makotojava.ncaabb.dao.SeasonAnalyticsDao;
27 | import com.makotojava.ncaabb.dao.SeasonAnalyticsJdbcDao;
28 | import com.makotojava.ncaabb.dao.SeasonDataDao;
29 | import com.makotojava.ncaabb.dao.SeasonDataJdbcDao;
30 | import com.makotojava.ncaabb.dao.TournamentAnalyticsDao;
31 | import com.makotojava.ncaabb.dao.TournamentAnalyticsJdbcDao;
32 | import com.makotojava.ncaabb.dao.TournamentResultDao;
33 | import com.makotojava.ncaabb.dao.TournamentResultJdbcDao;
34 | import com.makotojava.ncaabb.util.NetworkProperties;
35 |
36 | /**
37 | * Spring configuration class. Saves having to use XML files to configure Spring.
38 | *
39 | * @author J Steven Perry
40 | *
41 | */
42 | @Configuration
43 | @ComponentScan(basePackages = {
44 | "com.makotojava.ncaabb.dao.*"
45 | })
46 | @EnableTransactionManagement
47 | public class ApplicationConfig {
48 |
49 | @Bean(name = "dataSource")
50 | public DataSource getDataSource() {
51 | PGSimpleDataSource ret = new PGSimpleDataSource();
52 | //
53 | ret.setDatabaseName(NetworkProperties.getDatabaseName());
54 | ret.setPortNumber(5432);
55 | ret.setUser(NetworkProperties.getDatabaseUser());
56 |
57 | return ret;
58 | }
59 |
60 | @Bean(name = "seasonDataDao")
61 | public SeasonDataDao getSeasonDataDao() {
62 | return new SeasonDataJdbcDao(getDataSource());
63 | }
64 |
65 | @Bean(name = "tournamentResultDao")
66 | public TournamentResultDao getTournamentResultDao() {
67 | return new TournamentResultJdbcDao(getDataSource());
68 | }
69 |
70 | @Bean(name = "SeasonAnalyticsDao")
71 | public SeasonAnalyticsDao getSeasonAnalyticsDao() {
72 | return new SeasonAnalyticsJdbcDao(getDataSource());
73 | }
74 |
75 | @Bean(name = "tournamentAnalyticsDao")
76 | public TournamentAnalyticsDao getTournamentAnalyticsDao() {
77 | return new TournamentAnalyticsJdbcDao(getDataSource());
78 | }
79 |
80 | }
81 |
--------------------------------------------------------------------------------
/NcaaMarchMadness/src/main/java/com/makotojava/ncaabb/sqlgenerator/FieldGoalPercentageDefense.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2017 Makoto Consulting Group, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.makotojava.ncaabb.sqlgenerator;
17 |
18 | import java.math.BigDecimal;
19 | import java.math.RoundingMode;
20 | import java.util.List;
21 |
22 | import org.apache.log4j.Logger;
23 |
24 | public class FieldGoalPercentageDefense extends AbstractStrategy {
25 |
26 | private static final Logger LOG = Logger.getLogger(FieldGoalPercentageDefense.class);
27 |
28 | public static final String TABLE_NAME = "field_goal_percentage_defense";
29 |
30 | public final static String STATCAT_FIELD_GOAL_PERCENTAGE_DEFENSE = "Field-Goal Percentage Defense";
31 |
32 | public FieldGoalPercentageDefense() {
33 | super(FieldGoalPercentageDefense.STATCAT_FIELD_GOAL_PERCENTAGE_DEFENSE);
34 | }
35 |
36 | @Override
37 | public String generateSql(String year, List data) {
38 | //
39 | StringBuilder sb = new StringBuilder();
40 | LOG.debug("Generating SQL for stat cat => " + getStrategyName() + " and year => " + year);
41 | LOG.debug("There are " + data.size() + " lines of data to be processed...");
42 | for (String[] line : data) {
43 | String teamName = line[1];
44 | int numGames = Integer.valueOf(line[2]);
45 | int numFgMade = Integer.valueOf(line[4]);
46 | int numFgAtt = Integer.valueOf(line[5]);
47 | BigDecimal numFgPg = BigDecimal.valueOf((double)numFgMade/numGames).setScale(5, RoundingMode.HALF_UP);
48 | BigDecimal numFgAttPg = BigDecimal.valueOf((double)numFgAtt/numGames).setScale(5, RoundingMode.HALF_UP);
49 | BigDecimal fgPct = BigDecimal.valueOf((double)numFgMade/numFgAtt).setScale(5, RoundingMode.HALF_UP);
50 | String sql = "INSERT INTO " + /*SCHEMA_NAME + "." +*/ TABLE_NAME + "(" +
51 | "YEAR, TEAM_NAME, NUM_GAMES, NUM_OPP_FG_MADE, NUM_OPP_FG_ATTEMPTS, NUM_OPP_FG_PER_GAME, NUM_OPP_FG_ATTEMPTS_PER_GAME, OPP_FG_PERCENTAGE)"
52 | + "VALUES(" +
53 | Integer.valueOf(year) + "," +
54 | "'" + teamName + "'," +
55 | numGames + "," +
56 | numFgMade + "," +
57 | numFgAtt + "," +
58 | numFgPg.doubleValue() + "," +
59 | numFgAttPg.doubleValue() + "," +
60 | fgPct.doubleValue() +
61 | ");" + "\n"
62 | ;
63 | sb.append(sql);
64 | incrementNumberOfRowsProcessed();
65 | }
66 | return sb.toString();
67 | }
68 |
69 | }
70 |
--------------------------------------------------------------------------------
/NcaaMarchMadness/src/main/script/run-mlp-trainer.sh:
--------------------------------------------------------------------------------
1 | #!
2 | #
3 | # Script to run the MlpNetworkTrainer program.
4 | #
5 | # Set DEBUG to something other than true to turn it off
6 | DEBUG=true
7 |
8 | function usage {
9 | echo "Usage: $0 td_year [td_year2 ... td_yearN] v_year [,v_year2,...v_yearN]"
10 | echo "Description: creates training data for the specified years"
11 | echo "Where:"
12 | echo -e "\ttd_year1 is the first (and possibly only) year for which training data is to be used to train the network."
13 | echo -e "\tyear2 (optional) is the second year (if specified) for which training data is to be used to train the network."
14 | echo -e "\tyearN (optional) is the Nth year (if specified) for which training data is to be used to train the network."
15 | echo -e "\tv_year1..N is the comma-separated list of years against which the network is to be validated. (At least one"
16 | echo -e "\t\tv_year value is required)."
17 | echo "Examples:"
18 | echo "Train a network against data from 2011 through 2014 and validate against 2015 and 2016"
19 | echo -e "\t$0 2011 2012 2013 2014 2015,2016"
20 | echo "Train a network against data from 2010 through 2013 and validate against 2009, 2014, 2015 and 2016"
21 | echo -e "\t$0 2010 2011 2012 2013 2009,2014,2015,2016"
22 | echo
23 | }
24 |
25 | # Process number of arguments
26 | NUMARGS=$#
27 | if [ "$DEBUG" == "true" ]; then echo -e \\n"Number of arguments: $NUMARGS"; fi
28 | if [ "$NUMARGS" -eq 0 ]; then
29 | usage
30 | exit 1
31 | fi
32 | if [ "$DEBUG" == "true" ]; then echo "Script arguments: $@"; fi
33 |
34 | # Below is an example that works on my Mac.
35 | # Change this to match your source location.
36 | ROOT_DIR=/Users/sperry/home/development/projects/developerWorks/NcaaMarchMadness
37 |
38 | # Make sure ROOT_DIR is set or bail out
39 | if [ -z "$ROOT_DIR" ]
40 | then
41 | echo "ROOT_DIR is not set! This variable should be set to the source root of your project."
42 | echo "Make sure that you run a Maven build to create the necessary class files"
43 | echo "and library dependencies"
44 | exit 1
45 | fi
46 |
47 | if [ "$DEBUG" == "true" ]; then echo "ROOT_DIR = ${ROOT_DIR}"; fi
48 |
49 | # Set the lib directory as a convenience
50 | LIB_DIR=$ROOT_DIR/target/lib
51 |
52 | SPRING_FRAMEWORK_VERSION=4.3.6.RELEASE
53 |
54 | # Set the CLASSPATH to use.
55 | CP=\
56 | $LIB_DIR/neuroph-2.94.jar:\
57 | $LIB_DIR/postgresql-9.1-901-1.jdbc4.jar:\
58 | $LIB_DIR/commons-lang3-3.4.jar:\
59 | $LIB_DIR/spring-context-$SPRING_FRAMEWORK_VERSION.jar:\
60 | $LIB_DIR/spring-core-$SPRING_FRAMEWORK_VERSION.jar:\
61 | $LIB_DIR/spring-beans-$SPRING_FRAMEWORK_VERSION.jar:\
62 | $LIB_DIR/spring-aop-$SPRING_FRAMEWORK_VERSION.jar:\
63 | $LIB_DIR/spring-expression-$SPRING_FRAMEWORK_VERSION.jar:\
64 | $LIB_DIR/spring-jdbc-$SPRING_FRAMEWORK_VERSION.jar:\
65 | $LIB_DIR/spring-tx-$SPRING_FRAMEWORK_VERSION.jar:\
66 | $LIB_DIR/log4j-1.2.17.jar:\
67 | $LIB_DIR/jcl-over-slf4j-1.7.22.jar:\
68 | $LIB_DIR/slf4j-api-1.7.22.jar
69 |
70 | if [ "$DEBUG" == "true" ]; then echo "CLASSPATH = $CP"; fi
71 |
72 | # Fire up the program
73 | java -jar $ROOT_DIR/target/MarchMadness-1.0.0.jar $@
74 |
--------------------------------------------------------------------------------
/NcaaMarchMadness/src/main/java/com/makotojava/ncaabb/sqlgenerator/ThreePointPercentageDefense.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2017 Makoto Consulting Group, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.makotojava.ncaabb.sqlgenerator;
17 |
18 | import java.math.BigDecimal;
19 | import java.math.RoundingMode;
20 | import java.util.List;
21 |
22 | import org.apache.log4j.Logger;
23 |
24 | public class ThreePointPercentageDefense extends AbstractStrategy {
25 |
26 | private static final Logger LOG = Logger.getLogger(ThreePointPercentageDefense.class);
27 |
28 | public static final String TABLE_NAME = "three_point_percentage_defense";
29 |
30 | public final static String STATCAT_THREE_POINT_PERCENTAGE_DEFENSE = "Three Pt FG Defense";
31 |
32 | public ThreePointPercentageDefense() {
33 | super(ThreePointPercentageDefense.STATCAT_THREE_POINT_PERCENTAGE_DEFENSE);
34 | }
35 |
36 | @Override
37 | public String generateSql(String year, List data) {
38 | //
39 | StringBuilder sb = new StringBuilder();
40 | LOG.debug("Generating SQL for stat cat => " + getStrategyName() + " and year => " + year);
41 | LOG.debug("There are " + data.size() + " lines of data to be processed...");
42 | for (String[] line : data) {
43 | String teamName = line[1];
44 | int numGames = Integer.valueOf(line[2]);
45 | int numMade = Integer.valueOf(line[5]);
46 | int numAtt = Integer.valueOf(line[4]);// WTF, NCAA? These are switched.. inconsistent with all the other data...
47 | BigDecimal numAttPg = BigDecimal.valueOf((double)numAtt/numGames).setScale(5, RoundingMode.HALF_UP);
48 | BigDecimal numPg = BigDecimal.valueOf((double)numMade/numGames).setScale(5, RoundingMode.HALF_UP);
49 | BigDecimal pct = BigDecimal.valueOf((double)numMade/numAtt).setScale(5, RoundingMode.HALF_UP);
50 | String sql = "INSERT INTO " + /*SCHEMA_NAME + "." +*/ TABLE_NAME + "(" +
51 | "YEAR, TEAM_NAME, NUM_GAMES, NUM_OPP_3P_MADE, NUM_OPP_3P_ATTEMPTS, NUM_OPP_3P_PER_GAME, NUM_OPP_3P_ATTEMPTS_PER_GAME, OPP_3P_PERCENTAGE)"
52 | + "VALUES(" +
53 | Integer.valueOf(year) + "," +
54 | "'" + teamName + "'," +
55 | numGames + "," +
56 | numMade + "," +
57 | numAtt + "," +
58 | numPg.doubleValue() + "," +
59 | numAttPg.doubleValue() + "," +
60 | pct.doubleValue() +
61 | ");" + "\n"
62 | ;
63 | sb.append(sql);
64 | incrementNumberOfRowsProcessed();
65 | }
66 | return sb.toString();
67 | }
68 |
69 | }
70 |
--------------------------------------------------------------------------------
/NcaaMarchMadness/src/main/java/com/makotojava/ncaabb/sqlgenerator/TurnoverMargin.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2017 Makoto Consulting Group, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.makotojava.ncaabb.sqlgenerator;
17 |
18 | import java.math.BigDecimal;
19 | import java.math.RoundingMode;
20 | import java.util.List;
21 |
22 | import org.apache.log4j.Logger;
23 |
24 | public class TurnoverMargin extends AbstractStrategy {
25 |
26 | private static final Logger LOG = Logger.getLogger(ReboundMargin.class);
27 |
28 | public static final String TABLE_NAME = "turnover_margin";
29 |
30 | public final static String STATCAT_TURNOVER_MARGIN = "Turnover Margin";
31 |
32 | public TurnoverMargin() {
33 | super(TurnoverMargin.STATCAT_TURNOVER_MARGIN);
34 | }
35 |
36 | @Override
37 | public String generateSql(String year, List data) {
38 | StringBuilder sb = new StringBuilder();
39 | LOG.debug("Generating SQL for stat cat => " + getStrategyName() + " and year => " + year);
40 | LOG.debug("There are " + data.size() + " lines of data to be processed...");
41 | for (String[] line : data) {
42 | String teamName = line[1];
43 | int numGames = Integer.valueOf(line[2]);
44 | // Ignore W-L (don't care)
45 | int numOppTurnovers = Integer.valueOf(line[4]);
46 | int numTurnovers = Integer.valueOf(line[5]);
47 | // Ignore RATIO (will calculate ourselves to a greater level of precision)
48 | BigDecimal turnoversPerGame = BigDecimal.valueOf((double)numTurnovers/numGames).setScale(5, RoundingMode.HALF_UP);
49 | BigDecimal oppTurnoversPerGame = BigDecimal.valueOf((double)numOppTurnovers/numGames).setScale(5, RoundingMode.HALF_UP);
50 | BigDecimal turnoverMargin = turnoversPerGame.subtract(oppTurnoversPerGame).setScale(5, RoundingMode.HALF_UP);
51 | String sql = "INSERT INTO " + /*SCHEMA_NAME + "." + */TABLE_NAME + "(" +
52 | "YEAR, TEAM_NAME, NUM_GAMES, NUM_TURNOVERS, TURNOVERS_PER_GAME, OPP_NUM_TURNOVERS, OPP_TURNOVERS_PER_GAME, TURNOVER_MARGIN"
53 | + ")"
54 | + "VALUES(" +
55 | Integer.valueOf(year) + "," +
56 | "'" + teamName + "'," +
57 | numGames + "," +
58 | numTurnovers + "," +
59 | turnoversPerGame.doubleValue() + "," +
60 | numOppTurnovers + "," +
61 | oppTurnoversPerGame.doubleValue() + "," +
62 | turnoverMargin.doubleValue() +
63 | ");" + "\n"
64 | ;
65 | sb.append(sql);
66 | incrementNumberOfRowsProcessed();
67 | }
68 | return sb.toString();
69 | }
70 |
71 | }
72 |
--------------------------------------------------------------------------------
/NcaaMarchMadness/src/main/java/com/makotojava/ncaabb/sqlgenerator/ReboundMargin.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2017 Makoto Consulting Group, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.makotojava.ncaabb.sqlgenerator;
17 |
18 | import java.math.BigDecimal;
19 | import java.math.RoundingMode;
20 | import java.util.List;
21 |
22 | import org.apache.log4j.Logger;
23 |
24 | public class ReboundMargin extends AbstractStrategy {
25 |
26 | private static final Logger LOG = Logger.getLogger(ReboundMargin.class);
27 |
28 | public static final String TABLE_NAME = "rebound_margin";
29 |
30 | public final static String STATCAT_REBOUND_MARGIN = "Rebound Margin";
31 |
32 | public ReboundMargin() {
33 | super(ReboundMargin.STATCAT_REBOUND_MARGIN);
34 | }
35 |
36 | @Override
37 | public String generateSql(String year, List data) {
38 | StringBuilder sb = new StringBuilder();
39 | LOG.debug("Generating SQL for stat cat => " + getStrategyName() + " and year => " + year);
40 | LOG.debug("There are " + data.size() + " lines of data to be processed...");
41 | for (String[] line : data) {
42 | String teamName = line[1];
43 | int numGames = Integer.valueOf(line[2]);
44 | // Ignore W-L (don't care)
45 | int numRebounds = Integer.valueOf(line[4]);
46 | // Ignore RPG (will calculate ourselves to a greater level of precision)
47 | BigDecimal reboundsPerGame = BigDecimal.valueOf((double)numRebounds/numGames).setScale(5, RoundingMode.HALF_UP);
48 | int numOppRebounds = Integer.valueOf(line[6]);
49 | // Ignore Opponent Rebounds/Game (will calculate ourselves)
50 | BigDecimal oppReboundsPerGame = BigDecimal.valueOf((double)numOppRebounds/numGames).setScale(5, RoundingMode.HALF_UP);
51 | BigDecimal reboundMargin = reboundsPerGame.subtract(oppReboundsPerGame).setScale(5, RoundingMode.HALF_UP);
52 | String sql = "INSERT INTO " + /*SCHEMA_NAME + "." + */TABLE_NAME + "(" +
53 | "YEAR, TEAM_NAME, NUM_GAMES, NUM_REBOUNDS, REBOUNDS_PER_GAME, OPP_NUM_REBOUNDS, OPP_REBOUNDS_PER_GAME, REBOUND_MARGIN"
54 | + ")"
55 | + "VALUES(" +
56 | Integer.valueOf(year) + "," +
57 | "'" + teamName + "'," +
58 | numGames + "," +
59 | numRebounds + "," +
60 | reboundsPerGame.doubleValue() + "," +
61 | numOppRebounds + "," +
62 | oppReboundsPerGame.doubleValue() + "," +
63 | reboundMargin.doubleValue() +
64 | ");" + "\n"
65 | ;
66 | sb.append(sql);
67 | incrementNumberOfRowsProcessed();
68 | }
69 | return sb.toString();
70 | }
71 |
72 | }
73 |
--------------------------------------------------------------------------------
/NcaaMarchMadness/src/main/java/com/makotojava/ncaabb/dao/TournamentAnalyticsJdbcDao.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2017 Makoto Consulting Group, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.makotojava.ncaabb.dao;
17 |
18 | import java.sql.ResultSet;
19 | import java.sql.SQLException;
20 | import java.util.List;
21 |
22 | import javax.sql.DataSource;
23 |
24 | import org.apache.log4j.Logger;
25 | import org.springframework.jdbc.core.RowMapper;
26 | import org.springframework.jdbc.core.support.JdbcDaoSupport;
27 |
28 | import com.makotojava.ncaabb.model.TournamentAnalytics;
29 |
30 | /**
31 | * TournamentAnalyticsDao interface implementation specifically for Spring.
32 | *
33 | * @author J Steven Perry
34 | *
35 | */
36 | public class TournamentAnalyticsJdbcDao extends JdbcDaoSupport implements TournamentAnalyticsDao {
37 |
38 | private static final Logger log = Logger.getLogger(SeasonAnalyticsJdbcDao.class);
39 |
40 | private static final String TABLE_NAME = "v_tournament_analytics";
41 |
42 | public TournamentAnalyticsJdbcDao(DataSource dataSource) {
43 | this.setDataSource(dataSource);
44 | }
45 |
46 | @Override
47 | public TournamentAnalytics fetchByYear(Integer year) {
48 | TournamentAnalytics ret = null;
49 | //
50 | String sql = "SELECT * FROM " + TABLE_NAME + " WHERE year = ?";
51 | Object[] args = { year };
52 | //
53 | List results = getJdbcTemplate().query(sql, args, new TournamentAnalyticsRowMapper());
54 | //
55 | if (results.size() > 0) {
56 | if (results.size() > 1) {
57 | log.warn("Expected 1 result from query, instead got " + results.size() + "!");
58 | }
59 | ret = results.get(0);
60 | } else {
61 | log.warn("Requested year (" + year + ") does not exist in the DB!");
62 | }
63 | return ret;
64 | }
65 |
66 | /**
67 | * Maps the following columns
68 | * View "public.v_tournament_analytics"
69 | * Column | Type | Modifiers
70 | * -----------+---------+-----------
71 | * year | integer |
72 | * min_score | integer |
73 | * max_score | integer |
74 | *
75 | * @author sperry
76 | *
77 | */
78 | public class TournamentAnalyticsRowMapper implements RowMapper {
79 |
80 | @Override
81 | public TournamentAnalytics mapRow(ResultSet resultSet, int rowNum) throws SQLException {
82 | TournamentAnalytics ret = new TournamentAnalytics();
83 |
84 | ret.setYear(resultSet.getInt("year"));
85 | ret.setMinScore(resultSet.getInt("min_score"));
86 | ret.setMaxScore(resultSet.getInt("max_score"));
87 |
88 | return ret;
89 | }
90 |
91 | }
92 |
93 | }
94 |
--------------------------------------------------------------------------------
/NcaaMarchMadness/src/main/java/com/makotojava/ncaabb/sqlgenerator/TournamentResult.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2017 Makoto Consulting Group, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.makotojava.ncaabb.sqlgenerator;
17 |
18 | import java.util.Date;
19 | import java.util.List;
20 |
21 | import org.apache.commons.lang3.StringUtils;
22 | import org.apache.log4j.Logger;
23 |
24 | public class TournamentResult extends AbstractStrategy {
25 |
26 | private static final Logger LOG = Logger.getLogger(TournamentResult.class);
27 |
28 | public static final String TABLE_NAME = "tournament_result";
29 |
30 | // CONSTANTS for Statistics Categories. We use these to determine which
31 | /// SQL Generation strategy to employ, which will vary for each type
32 | /// of data block (i.e., different column values).
33 | public final static String STATCAT_TOURNAMENT_RESULTS = "Tournament Results";
34 |
35 | public TournamentResult() {
36 | super(TournamentResult.STATCAT_TOURNAMENT_RESULTS);
37 | }
38 |
39 | @Override
40 | public String generateSql(String year, List data) {
41 | StringBuilder sb = new StringBuilder();
42 | LOG.debug("Generating SQL for stat cat => " + getStrategyName() + " and year => " + year);
43 | LOG.debug("There are " + data.size() + " lines of data to be processed...");
44 | for (String[] line : data) {
45 | Date gameDate = convertStringToDate(line[0]);
46 | String winningTeamName = StringUtils.strip(line[1]);
47 | int winningTeamScore = Integer.valueOf(StringUtils.strip(line[2]));
48 | String losingTeamName = StringUtils.strip(line[3]);
49 | int losingTeamScore = Integer.valueOf(StringUtils.strip(line[4]));
50 | // Now for the SQL...
51 | String sql = "INSERT INTO " + /*SCHEMA_NAME + "." + */TABLE_NAME + "(" +
52 | // YEAR INTEGER NOT NULL,
53 | // GAME_DATE DATE NOT NULL,
54 | // WINNING_TEAM_NAME VARCHAR(64) NOT NULL,
55 | // WINNING_SCORE INTEGER NOT NULL,
56 | // LOSING_TEAM_NAME VARCHAR(64) NOT NULL,
57 | // LOSING_SCORE INTEGER NOT NULL
58 | "YEAR, GAME_DATE, WINNING_TEAM_NAME, WINNING_SCORE, LOSING_TEAM_NAME, LOSING_SCORE"
59 | + ")"
60 | + "VALUES(" +
61 | Integer.valueOf(year) + "," +
62 | "'" + gameDate.toString() + "'," +
63 | "'" + winningTeamName + "'," +
64 | Integer.valueOf(winningTeamScore) + "," +
65 | "'" + losingTeamName + "'," +
66 | Integer.valueOf(losingTeamScore) +
67 | ");" + "\n"
68 | ;
69 | sb.append(sql);
70 | incrementNumberOfRowsProcessed();
71 | }
72 | return sb.toString();
73 | }
74 |
75 | }
76 |
--------------------------------------------------------------------------------
/perishable-network/models/perishable.cto:
--------------------------------------------------------------------------------
1 | /**
2 | * A business network for shipping perishable goods
3 | * The cargo is temperature controlled and contracts
4 | * can be negociated based on the temperature
5 | * readings received for the cargo
6 | */
7 |
8 | namespace org.acme.shipping.perishable
9 |
10 | /**
11 | * The type of perishable product being shipped
12 | */
13 | enum ProductType {
14 | o BANANAS
15 | o APPLES
16 | o PEARS
17 | o PEACHES
18 | o COFFEE
19 | }
20 |
21 | /**
22 | * The status of a shipment
23 | */
24 | enum ShipmentStatus {
25 | o CREATED
26 | o IN_TRANSIT
27 | o ARRIVED
28 | }
29 |
30 | /**
31 | * An abstract transaction that is related to a Shipment
32 | */
33 | abstract transaction ShipmentTransaction {
34 | --> Shipment shipment
35 | }
36 |
37 | /**
38 | * An temperature reading for a shipment. E.g. received from a
39 | * device within a temperature controlled shipping container
40 | */
41 | transaction TemperatureReading extends ShipmentTransaction {
42 | o Double centigrade
43 | }
44 |
45 | /**
46 | * A notification that a shipment has been received by the
47 | * importer and that funds should be transferred from the importer
48 | * to the grower to pay for the shipment.
49 | */
50 | transaction ShipmentReceived extends ShipmentTransaction {
51 | }
52 |
53 | /**
54 | * A shipment being tracked as an asset on the ledger
55 | */
56 | asset Shipment identified by shipmentId {
57 | o String shipmentId
58 | o ProductType type
59 | o ShipmentStatus status
60 | o Long unitCount
61 | o TemperatureReading[] temperatureReadings optional
62 | --> Contract contract
63 | }
64 |
65 | /**
66 | * Defines a contract between a Grower and an Importer to ship using
67 | * a Shipper, paying a set unit price. The unit price is multiplied by
68 | * a penality factor proportional to the deviation from the min and max
69 | * negociated temperatures for the shipment.
70 | */
71 | asset Contract identified by contractId {
72 | o String contractId
73 | --> Grower grower
74 | --> Shipper shipper
75 | --> Importer importer
76 | o DateTime arrivalDateTime
77 | o Double unitPrice
78 | o Double minTemperature
79 | o Double maxTemperature
80 | o Double minPenaltyFactor
81 | o Double maxPenaltyFactor
82 | }
83 |
84 | /**
85 | * A concept for a simple street address
86 | */
87 | concept Address {
88 | o String city optional
89 | o String country
90 | o String street optional
91 | o String zip optional
92 | }
93 |
94 | /**
95 | * An abstract participant type in this business network
96 | */
97 | abstract participant Business identified by email {
98 | o String email
99 | o Address address
100 | o Double accountBalance
101 | }
102 |
103 | /**
104 | * A Grower is a type of participant in the network
105 | */
106 | participant Grower extends Business {
107 | }
108 |
109 | /**
110 | * A Shipper is a type of participant in the network
111 | */
112 | participant Shipper extends Business {
113 | }
114 |
115 | /**
116 | * An Importer is a type of participant in the network
117 | */
118 | participant Importer extends Business {
119 | }
120 |
121 | /**
122 | * JUST FOR INITIALIZING A DEMO
123 | */
124 | transaction SetupDemo {
125 | }
126 |
--------------------------------------------------------------------------------
/iot-perishable-network-advanced/features/grower.feature:
--------------------------------------------------------------------------------
1 | Feature: Tests related to Growers
2 |
3 | Background:
4 | Given I have deployed the business network definition ..
5 | And I have added the following participants
6 | """
7 | [
8 | {"$class":"org.acme.shipping.perishable.Grower", "email":"grower@email.com", "address":{"$class":"org.acme.shipping.perishable.Address", "country":"USA"}, "accountBalance":0},
9 | {"$class":"org.acme.shipping.perishable.Shipper", "email":"shipper@email.com", "address":{"$class":"org.acme.shipping.perishable.Address", "country":"Paname"}, "accountBalance":0}
10 | ]
11 | """
12 | And I have issued the participant org.acme.shipping.perishable.Grower#grower@email.com with the identity grower1
13 | And I have issued the participant org.acme.shipping.perishable.Shipper#shipper@email.com with the identity shipper1
14 | And I have added the following asset of type org.acme.shipping.perishable.Contract
15 | | contractId | grower | shipper | importer | arrivalDateTime | unitPrice | minTemperature | maxTemperature | minPenaltyFactor | maxPenaltyFactor |
16 | | CON_001 | grower@email.com | shipper@email.com | supermarket@email.com | 10/26/2018 00:00 | 0.5 | 2 | 10 | 0.2 | 0.1 |
17 | And I have added the following asset of type org.acme.shipping.perishable.Shipment
18 | | shipmentId | type | status | unitCount | contract |
19 | | SHIP_001 | BANANAS | IN_TRANSIT | 5000 | CON_001 |
20 | When I use the identity grower1
21 |
22 | Scenario: grower1 can read Grower assets
23 | Then I should have the following participants
24 | """
25 | [
26 | {"$class":"org.acme.shipping.perishable.Grower", "email":"grower@email.com", "address":{"$class":"org.acme.shipping.perishable.Address", "country":"USA"}, "accountBalance":0}
27 | ]
28 | """
29 |
30 | Scenario: grower1 invokes the ShipmentPacked transaction
31 | And I submit the following transaction of type org.acme.shipping.perishable.ShipmentPacked
32 | | shipment |
33 | | SHIP_001 |
34 | Then I should have received the following event of type org.acme.shipping.perishable.ShipmentPackedEvent
35 | | message | shipment |
36 | | Shipment packed for shipment SHIP_001 | SHIP_001 |
37 |
38 | Scenario: shipper1 cannot read Grower assets
39 | When I use the identity shipper1
40 | And I should have the following participants
41 | """
42 | [
43 | {"$class":"org.acme.shipping.perishable.Grower", "email":"grower@email.com", "address":{"$class":"org.acme.shipping.perishable.Address", "country":"USA"}, "accountBalance":0}
44 | ]
45 | """
46 | Then I should get an error matching /Object with ID .* does not exist/
47 |
48 | Scenario: shipper1 cannot invoke the ShipmentPacked transaction
49 | When I use the identity shipper1
50 | And I submit the following transaction of type org.acme.shipping.perishable.ShipmentPacked
51 | | shipment |
52 | | SHIP_001 |
53 | Then I should get an error matching /Participant .* does not have 'CREATE' access to resource/
54 |
--------------------------------------------------------------------------------
/NcaaMarchMadness/src/main/sql/build_db.sql:
--------------------------------------------------------------------------------
1 | --
2 | -- The main build script. Use this script to build a fresh database.
3 | -- If you need to rebuild the DB, dropping tables and views
4 | -- will be required, and you should run rebuild.sh
5 | --
6 | \set ROOT_DIR ''/Users/sperry/home/development/projects/developerWorks/NcaaMarchMadness/src/main''
7 | \set SQL_ROOT_DIR :ROOT_DIR/sql
8 | \set DATA_ROOT_DIR :ROOT_DIR/data
9 | \set LOAD_SCRIPT_ROOT_DIR ''/Users/sperry/l/MarchMadness/data''
10 |
11 | -- Tee output to log file
12 | \o :LOAD_SCRIPT_ROOT_DIR/DB_BUILD_LOG.txt
13 |
14 | \echo 'BUILDING DB...'
15 | \qecho 'BUILDING DB...'
16 |
17 | \echo 'Script variables:'
18 | \echo 'ROOT_DIR ==> ' :ROOT_DIR
19 | \echo 'SQL_ROOT_DIR ==> ' :SQL_ROOT_DIR
20 | \echo 'DATA_ROOT_DIR ==> ' :DATA_ROOT_DIR
21 | \echo 'LOAD_SCRIPT_ROOT_DIR ==> ' :LOAD_SCRIPT_ROOT_DIR
22 |
23 | \qecho 'Script variables:'
24 | \qecho 'ROOT_DIR ==> ' :ROOT_DIR
25 | \qecho 'SQL_ROOT_DIR ==> ' :SQL_ROOT_DIR
26 | \qecho 'DATA_ROOT_DIR ==> ' :DATA_ROOT_DIR
27 | \qecho 'LOAD_SCRIPT_ROOT_DIR ==> ' :LOAD_SCRIPT_ROOT_DIR
28 |
29 | \echo 'CREATING ALL TABLES...'
30 | \qecho 'CREATING ALL TABLES...'
31 | \i :SQL_ROOT_DIR/create_tables.sql
32 |
33 | \echo 'CREATING ALL VIEWS...'
34 | \qecho 'CREATING ALL VIEWS...'
35 | \i :SQL_ROOT_DIR/create_views.sql
36 |
37 | \echo 'LOADING ALL TABLES:'
38 | \qecho 'LOADING ALL TABLES:'
39 |
40 | \echo 'YEAR: 2010...'
41 | \qecho 'YEAR: 2010...'
42 | \set YEAR 2010
43 | \i :LOAD_SCRIPT_ROOT_DIR/load_season_data_:YEAR.sql
44 | \i :DATA_ROOT_DIR/load_tournament_participants-2010.sql
45 |
46 | \echo 'YEAR: 2011...'
47 | \qecho 'YEAR: 2011...'
48 | \set YEAR 2011
49 | \i :LOAD_SCRIPT_ROOT_DIR/load_season_data_:YEAR.sql
50 | \i :DATA_ROOT_DIR/load_tournament_participants-2011.sql
51 |
52 | \echo 'YEAR: 2012...'
53 | \qecho 'YEAR: 2012...'
54 | \set YEAR 2012
55 | \i :LOAD_SCRIPT_ROOT_DIR/load_season_data_:YEAR.sql
56 | \i :DATA_ROOT_DIR/load_tournament_participants-2012.sql
57 |
58 | \echo 'YEAR: 2013...'
59 | \qecho 'YEAR: 2013...'
60 | \set YEAR 2013
61 | \i :LOAD_SCRIPT_ROOT_DIR/load_season_data_:YEAR.sql
62 | \i :DATA_ROOT_DIR/load_tournament_participants-2013.sql
63 |
64 | \echo 'YEAR: 2014...'
65 | \qecho 'YEAR: 2014...'
66 | \set YEAR 2014
67 | \i :LOAD_SCRIPT_ROOT_DIR/load_season_data_:YEAR.sql
68 | \i :DATA_ROOT_DIR/load_tournament_participants-2014.sql
69 |
70 | \echo 'YEAR: 2015...'
71 | \qecho 'YEAR: 2015...'
72 | \set YEAR 2015
73 | \i :LOAD_SCRIPT_ROOT_DIR/load_season_data_:YEAR.sql
74 | \i :DATA_ROOT_DIR/load_tournament_participants-2015.sql
75 |
76 | \echo 'YEAR: 2016...'
77 | \qecho 'YEAR: 2016...'
78 | \set YEAR 2016
79 | \i :LOAD_SCRIPT_ROOT_DIR/load_season_data_:YEAR.sql
80 | \i :DATA_ROOT_DIR/load_tournament_participants-2016.sql
81 |
82 | \echo 'YEAR: 2017...'
83 | \qecho 'YEAR: 2017...'
84 | \set YEAR 2017
85 | \i :LOAD_SCRIPT_ROOT_DIR/load_season_data_:YEAR.sql
86 | \i :DATA_ROOT_DIR/load_tournament_participants-2017.sql
87 |
88 | \echo 'LOADING TOURNAMENT RESULT DATA FOR ALL YEARS...'
89 | \qecho 'LOADING TOURNAMENT RESULT DATA FOR ALL YEARS...'
90 | \i :SQL_ROOT_DIR/load_tournament_result.sql
91 |
92 | \echo 'FIND MISSING TEAM NAMES...'
93 | \qecho 'FIND MISSING TEAM NAMES...'
94 | \i :SQL_ROOT_DIR/find_missing_team_names.sql
95 |
96 | --
97 | \echo 'DATABASE BUILD COMPLETE.'
98 | \qecho 'DATABASE BUILD COMPLETE.'
99 | -- Turn off output to log file
100 | \o
101 |
--------------------------------------------------------------------------------
/NcaaMarchMadness/src/test/java/com/makotojava/ncaabb/dao/TournamentResultJdbcDaoTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2017 Makoto Consulting Group, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.makotojava.ncaabb.dao;
17 |
18 | import static org.junit.Assert.assertEquals;
19 |
20 | import java.util.List;
21 |
22 | import org.apache.log4j.Logger;
23 | import org.junit.Before;
24 | import org.junit.Test;
25 | import org.springframework.context.ApplicationContext;
26 | import org.springframework.context.annotation.AnnotationConfigApplicationContext;
27 |
28 | import com.makotojava.ncaabb.model.TournamentResult;
29 | import com.makotojava.ncaabb.springconfig.ApplicationConfig;
30 |
31 | public class TournamentResultJdbcDaoTest {
32 |
33 | private static final Logger log = Logger.getLogger(SeasonDataJdbcDaoTest.class);
34 |
35 | private ApplicationContext applicationContext;
36 | private TournamentResultDao classUnderTest;
37 |
38 | @Before
39 | public void setUp() throws Exception {
40 | applicationContext = new AnnotationConfigApplicationContext(ApplicationConfig.class);
41 | classUnderTest = applicationContext.getBean(TournamentResultDao.class);
42 | }
43 |
44 | @Test
45 | public void testFetchAllByYear_2011() {
46 | log.info("*** BEGIN Test ***");
47 | Integer year = 2011;
48 |
49 | List results = classUnderTest.fetchAllByYear(year);
50 | assertEquals(67, results.size());
51 | log.info("*** END Test ***");
52 | }
53 |
54 | @Test
55 | public void testFetchAllByYear_2012() {
56 | log.info("*** BEGIN Test ***");
57 | Integer year = 2012;
58 |
59 | List results = classUnderTest.fetchAllByYear(year);
60 | assertEquals(67, results.size());
61 | log.info("*** END Test ***");
62 | }
63 |
64 | @Test
65 | public void testFetchAllByYear_2013() {
66 | log.info("*** BEGIN Test ***");
67 | Integer year = 2013;
68 |
69 | List results = classUnderTest.fetchAllByYear(year);
70 | assertEquals(67, results.size());
71 | log.info("*** END Test ***");
72 | }
73 |
74 | @Test
75 | public void testFetchAllByYear_2014() {
76 | log.info("*** BEGIN Test ***");
77 | Integer year = 2014;
78 |
79 | List results = classUnderTest.fetchAllByYear(year);
80 | assertEquals(67, results.size());
81 | log.info("*** END Test ***");
82 | }
83 |
84 | @Test
85 | public void testFetchAllByYear_2015() {
86 | log.info("*** BEGIN Test ***");
87 | Integer year = 2015;
88 |
89 | List results = classUnderTest.fetchAllByYear(year);
90 | assertEquals(67, results.size());
91 | log.info("*** END Test ***");
92 | }
93 |
94 | @Test
95 | public void testFetchAllByYear_2016() {
96 | log.info("*** BEGIN Test ***");
97 | Integer year = 2016;
98 |
99 | List results = classUnderTest.fetchAllByYear(year);
100 | assertEquals(67, results.size());
101 | log.info("*** END Test ***");
102 | }
103 |
104 | }
105 |
--------------------------------------------------------------------------------
/iot-perishable-network-advanced/features/shipper.feature:
--------------------------------------------------------------------------------
1 | Feature: Tests related to Shippers
2 |
3 | Background:
4 | Given I have deployed the business network definition ..
5 | And I have added the following participants
6 | """
7 | [
8 | {"$class":"org.acme.shipping.perishable.Grower", "email":"grower@email.com", "address":{"$class":"org.acme.shipping.perishable.Address", "country":"USA"}, "accountBalance":0},
9 | {"$class":"org.acme.shipping.perishable.Shipper", "email":"shipper@email.com", "address":{"$class":"org.acme.shipping.perishable.Address", "country":"Paname"}, "accountBalance":0}
10 | ]
11 | """
12 | And I have issued the participant org.acme.shipping.perishable.Grower#grower@email.com with the identity grower1
13 | And I have issued the participant org.acme.shipping.perishable.Shipper#shipper@email.com with the identity shipper1
14 | And I have added the following asset of type org.acme.shipping.perishable.Contract
15 | | contractId | grower | shipper | importer | arrivalDateTime | unitPrice | minTemperature | maxTemperature | minPenaltyFactor | maxPenaltyFactor |
16 | | CON_001 | grower@email.com | shipper@email.com | supermarket@email.com | 10/26/2018 00:00 | 0.5 | 2 | 10 | 0.2 | 0.1 |
17 | And I have added the following asset of type org.acme.shipping.perishable.Shipment
18 | | shipmentId | type | status | unitCount | contract |
19 | | SHIP_001 | BANANAS | IN_TRANSIT | 5000 | CON_001 |
20 | When I use the identity shipper1
21 |
22 | Scenario: shipper1 can read Shipper assets
23 | Then I should have the following participants
24 | """
25 | [
26 | {"$class":"org.acme.shipping.perishable.Shipper", "email":"shipper@email.com", "address":{"$class":"org.acme.shipping.perishable.Address", "country":"Paname"}, "accountBalance":0}
27 | ]
28 | """
29 |
30 | Scenario: shipper1 invokes the ShipmentPickup transaction
31 | And I submit the following transaction of type org.acme.shipping.perishable.ShipmentPickup
32 | | shipment |
33 | | SHIP_001 |
34 | Then I should have received the following event of type org.acme.shipping.perishable.ShipmentPickupEvent
35 | | message | shipment |
36 | | Shipment picked up for shipment SHIP_001 | SHIP_001 |
37 |
38 | Scenario: shipper1 invokes the ShipmentLoaded transaction
39 | And I submit the following transaction of type org.acme.shipping.perishable.ShipmentLoaded
40 | | shipment |
41 | | SHIP_001 |
42 | Then I should have received the following event of type org.acme.shipping.perishable.ShipmentLoadedEvent
43 | | message | shipment |
44 | | Shipment loaded for shipment SHIP_001 | SHIP_001 |
45 |
46 | Scenario: grower1 cannot invoke the ShipmentPickup transaction
47 | When I use the identity grower1
48 | And I submit the following transaction of type org.acme.shipping.perishable.ShipmentPickup
49 | | shipment |
50 | | SHIP_001 |
51 | Then I should get an error matching /Participant .* does not have 'CREATE' access to resource/
52 |
53 | Scenario: grower1 cannot invoke the ShipmentPickup transaction
54 | When I use the identity grower1
55 | And I submit the following transaction of type org.acme.shipping.perishable.ShipmentLoaded
56 | | shipment |
57 | | SHIP_001 |
58 | Then I should get an error matching /Participant .* does not have 'CREATE' access to resource/
59 |
--------------------------------------------------------------------------------
/NcaaMarchMadness/src/main/java/com/makotojava/ncaabb/dao/TournamentResultJdbcDao.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2017 Makoto Consulting Group, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.makotojava.ncaabb.dao;
17 |
18 | import java.sql.ResultSet;
19 | import java.sql.SQLException;
20 | import java.util.List;
21 |
22 | import javax.sql.DataSource;
23 |
24 | import org.apache.commons.lang3.builder.ReflectionToStringBuilder;
25 | import org.apache.log4j.Logger;
26 | import org.springframework.jdbc.core.RowMapper;
27 | import org.springframework.jdbc.core.support.JdbcDaoSupport;
28 |
29 | import com.makotojava.ncaabb.model.TournamentResult;
30 |
31 | /**
32 | * TournamentResultDao interface implementation specifically for Spring.
33 | *
34 | * @author J Steven Perry
35 | *
36 | */
37 | public class TournamentResultJdbcDao extends JdbcDaoSupport implements TournamentResultDao {
38 |
39 | private static final Logger log = Logger.getLogger(TournamentResultJdbcDao.class);
40 |
41 | private static final String TABLE_NAME = "tournament_result";
42 |
43 | public TournamentResultJdbcDao(DataSource dataSource) {
44 | this.setDataSource(dataSource);
45 | }
46 |
47 | @Override
48 | public List fetchAllByYear(Integer year) {
49 | String sql = "SELECT t.* FROM " + TABLE_NAME + " t WHERE t.year = ? ORDER BY t.game_date";
50 | Object[] args = { year };
51 | // Run the query
52 | List results = getJdbcTemplate().query(sql, new TournamentResultRowMapper(), args);
53 | return results;
54 | }
55 |
56 | /**
57 | * Maps the following table:
58 | Table "public.tournament_result"
59 | Column | Type | Modifiers
60 | -------------------+-----------------------+----------------------------------------------------------------
61 | id | integer | not null default nextval('tournament_result_id_seq'::regclass)
62 | year | integer | not null
63 | game_date | date | not null
64 | winning_team_name | character varying(64) | not null
65 | winning_score | integer | not null
66 | losing_team_name | character varying(64) | not null
67 | losing_score | integer | not null
68 | Indexes:
69 | "tournament_result_pkey" PRIMARY KEY, btree (id)
70 | * @author sperry
71 | *
72 | */
73 | public class TournamentResultRowMapper implements RowMapper {
74 |
75 | @Override
76 | public TournamentResult mapRow(ResultSet resultSet, int rowNum) throws SQLException {
77 | TournamentResult ret = new TournamentResult();
78 | //
79 | ret.setId(resultSet.getInt("id"));
80 | ret.setYear(resultSet.getInt("year"));
81 | ret.setGameDate(resultSet.getDate("game_date"));
82 | ret.setWinningTeamName(resultSet.getString("winning_team_name"));
83 | ret.setWinningScore(resultSet.getInt("winning_score"));
84 | ret.setLosingTeamName(resultSet.getString("losing_team_name"));
85 | ret.setLosingScore(resultSet.getInt("losing_score"));
86 | //
87 | if (log.isTraceEnabled()) {
88 | log.trace("Mapped row number " + rowNum + ", Object: " + ReflectionToStringBuilder.toString(ret));
89 | }
90 | //
91 | return ret;
92 | }
93 |
94 | }
95 |
96 | }
97 |
--------------------------------------------------------------------------------
/NcaaMarchMadness/src/main/java/com/makotojava/ncaabb/model/TournamentResult.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2017 Makoto Consulting Group, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.makotojava.ncaabb.model;
17 |
18 | import java.util.Date;
19 |
20 | /**
21 | * This class represents the result of a single historical tournament game
22 | * played between two teams. In basketball there is always a winner and a loser.
23 | *
24 | * The interpretations of the fields should be pretty obvious based on their
25 | * names. Or maybe not.
26 | *
27 | * @author J Steven Perry
28 | *
29 | * Model object for the PostgreSQL table that has the following structure:
30 | *
31 | *
32 | * Table "public.tournament_results"
33 | * Column | Type | Modifiers
34 | * -------------------+-----------------------+-----------------------------------------------------------------
35 | * id | integer | not null default nextval('tournament_results_id_seq'::regclass)
36 | * year | integer | not null
37 | * game_date | date | not null
38 | * winning_team_name | character varying(64) | not null
39 | * winning_score | integer | not null
40 | * losing_team_name | character varying(64) | not null
41 | * losing_score | integer | not null
42 | * Indexes:
43 | * "tournament_results_pkey" PRIMARY KEY, btree (id)
44 | */
45 | public class TournamentResult implements Comparable {
46 |
47 | private Integer id;
48 | private Integer year;
49 | private Date gameDate;
50 | private String winningTeamName;
51 | private Integer winningScore;
52 | private String losingTeamName;
53 | private Integer losingScore;
54 |
55 | public TournamentResult() {
56 | // Nothing to do
57 | }
58 |
59 | public Integer getId() {
60 | return id;
61 | }
62 |
63 | public void setId(Integer id) {
64 | this.id = id;
65 | }
66 |
67 | public Integer getYear() {
68 | return year;
69 | }
70 |
71 | public void setYear(Integer year) {
72 | this.year = year;
73 | }
74 |
75 | public Date getGameDate() {
76 | return gameDate;
77 | }
78 |
79 | public void setGameDate(Date gameDate) {
80 | this.gameDate = gameDate;
81 | }
82 |
83 | public String getWinningTeamName() {
84 | return winningTeamName;
85 | }
86 |
87 | public void setWinningTeamName(String winningTeamName) {
88 | this.winningTeamName = winningTeamName;
89 | }
90 |
91 | public Integer getWinningScore() {
92 | return winningScore;
93 | }
94 |
95 | public void setWinningScore(Integer winningScore) {
96 | this.winningScore = winningScore;
97 | }
98 |
99 | public String getLosingTeamName() {
100 | return losingTeamName;
101 | }
102 |
103 | public void setLosingTeamName(String losingTeamName) {
104 | this.losingTeamName = losingTeamName;
105 | }
106 |
107 | public Integer getLosingScore() {
108 | return losingScore;
109 | }
110 |
111 | public void setLosingScore(Integer losingScore) {
112 | this.losingScore = losingScore;
113 | }
114 |
115 | @Override
116 | public int compareTo(TournamentResult o) {
117 | int ret = o.getGameDate().compareTo(getGameDate());
118 | if (ret == 0) {
119 | ret = o.getWinningTeamName().compareTo(getWinningTeamName());
120 | }
121 | if (ret == 0) {
122 | ret = o.getLosingTeamName().compareTo(getLosingTeamName());
123 | }
124 | return ret;
125 | }
126 |
127 | }
128 |
--------------------------------------------------------------------------------
/NcaaMarchMadness/src/test/java/com/makotojava/ncaabb/dao/SeasonAnalyticsJdbcDaoTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2017 Makoto Consulting Group, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.makotojava.ncaabb.dao;
17 |
18 | import static org.junit.Assert.assertNotNull;
19 |
20 | import org.apache.log4j.Logger;
21 | import org.junit.Before;
22 | import org.junit.Test;
23 | import org.springframework.context.ApplicationContext;
24 | import org.springframework.context.annotation.AnnotationConfigApplicationContext;
25 |
26 | import com.makotojava.ncaabb.model.SeasonAnalytics;
27 | import com.makotojava.ncaabb.springconfig.ApplicationConfig;
28 |
29 | public class SeasonAnalyticsJdbcDaoTest {
30 |
31 | private static final Logger log = Logger.getLogger(SeasonAnalyticsJdbcDaoTest.class);
32 |
33 | private ApplicationContext applicationContext;
34 | private SeasonAnalyticsDao classUnderTest;
35 |
36 | @Before
37 | public void setUp() throws Exception {
38 | applicationContext = new AnnotationConfigApplicationContext(ApplicationConfig.class);
39 | classUnderTest = applicationContext.getBean(SeasonAnalyticsDao.class);
40 | }
41 |
42 | @Test
43 | public void testFetchByYear_2010() {
44 | log.info("*** BEGIN Test ***");
45 | Integer year = 2010;
46 | SeasonAnalytics seasonAnalytics = classUnderTest.fetchByYear(year);
47 | assertNotNull(seasonAnalytics);
48 | log.info("*** END Test ***");
49 | }
50 |
51 | @Test
52 | public void testFetchByYear_2011() {
53 | log.info("*** BEGIN Test ***");
54 | Integer year = 2011;
55 | SeasonAnalytics seasonAnalytics = classUnderTest.fetchByYear(year);
56 | assertNotNull(seasonAnalytics);
57 | log.info("*** END Test ***");
58 | }
59 |
60 | @Test
61 | public void testFetchByYear_2012() {
62 | log.info("*** BEGIN Test ***");
63 | Integer year = 2012;
64 | SeasonAnalytics seasonAnalytics = classUnderTest.fetchByYear(year);
65 | assertNotNull(seasonAnalytics);
66 | log.info("*** END Test ***");
67 | }
68 |
69 | @Test
70 | public void testFetchByYear_2013() {
71 | log.info("*** BEGIN Test ***");
72 | Integer year = 2013;
73 | SeasonAnalytics seasonAnalytics = classUnderTest.fetchByYear(year);
74 | assertNotNull(seasonAnalytics);
75 | log.info("*** END Test ***");
76 | }
77 |
78 | @Test
79 | public void testFetchByYear_2014() {
80 | log.info("*** BEGIN Test ***");
81 | Integer year = 2014;
82 | SeasonAnalytics seasonAnalytics = classUnderTest.fetchByYear(year);
83 | assertNotNull(seasonAnalytics);
84 | log.info("*** END Test ***");
85 | }
86 |
87 | @Test
88 | public void testFetchByYear_2015() {
89 | log.info("*** BEGIN Test ***");
90 | Integer year = 2015;
91 | SeasonAnalytics seasonAnalytics = classUnderTest.fetchByYear(year);
92 | assertNotNull(seasonAnalytics);
93 | log.info("*** END Test ***");
94 | }
95 |
96 | @Test
97 | public void testFetchByYear_2016() {
98 | log.info("*** BEGIN Test ***");
99 | Integer year = 2016;
100 | SeasonAnalytics seasonAnalytics = classUnderTest.fetchByYear(year);
101 | assertNotNull(seasonAnalytics);
102 | log.info("*** END Test ***");
103 | }
104 |
105 | @Test
106 | public void testFetchByYear_2017() {
107 | log.info("*** BEGIN Test ***");
108 | Integer year = 2017;
109 | SeasonAnalytics seasonAnalytics = classUnderTest.fetchByYear(year);
110 | assertNotNull(seasonAnalytics);
111 | log.info("*** END Test ***");
112 | }
113 |
114 | }
115 |
--------------------------------------------------------------------------------
/iot-perishable-network/models/perishable.cto:
--------------------------------------------------------------------------------
1 | /**
2 | * A business network for shipping perishable goods
3 | * The cargo is temperature controlled and contracts
4 | * can be negociated based on the temperature
5 | * readings received for the cargo
6 | */
7 |
8 | namespace org.acme.shipping.perishable
9 |
10 | /**
11 | * The type of perishable product being shipped
12 | */
13 | enum ProductType {
14 | o BANANAS
15 | o APPLES
16 | o PEARS
17 | o PEACHES
18 | o COFFEE
19 | }
20 |
21 | /**
22 | * The status of a shipment
23 | */
24 | enum ShipmentStatus {
25 | o CREATED
26 | o IN_TRANSIT
27 | o ARRIVED
28 | }
29 |
30 | /**
31 | * Directions of the compass
32 | */
33 | enum CompassDirection {
34 | o N
35 | o S
36 | o E
37 | o W
38 | }
39 |
40 | /**
41 | * An abstract transaction that is related to a Shipment
42 | */
43 | abstract transaction ShipmentTransaction {
44 | --> Shipment shipment
45 | }
46 |
47 | /**
48 | * An temperature reading for a shipment. E.g. received from a
49 | * device within a temperature controlled shipping container
50 | */
51 | transaction TemperatureReading extends ShipmentTransaction {
52 | o Double centigrade
53 | }
54 |
55 | /**
56 | * A GPS reading for a shipment. E.g. received from a device
57 | * within a shipping container
58 | */
59 | transaction GpsReading extends ShipmentTransaction {
60 | o String readingTime
61 | o String readingDate
62 | o String latitude
63 | o CompassDirection latitudeDir
64 | o String longitude
65 | o CompassDirection longitudeDir
66 | }
67 |
68 | /**
69 | * A notification that a shipment has been received by the
70 | * importer and that funds should be transferred from the importer
71 | * to the grower to pay for the shipment.
72 | */
73 | transaction ShipmentReceived extends ShipmentTransaction {
74 | }
75 |
76 | /**
77 | * A shipment being tracked as an asset on the ledger
78 | */
79 | asset Shipment identified by shipmentId {
80 | o String shipmentId
81 | o ProductType type
82 | o ShipmentStatus status
83 | o Long unitCount
84 | --> Contract contract
85 | o TemperatureReading[] temperatureReadings optional
86 | o GpsReading[] gpsReadings optional
87 | }
88 |
89 | /**
90 | * Defines a contract between a Grower and an Importer to ship using
91 | * a Shipper, paying a set unit price. The unit price is multiplied by
92 | * a penality factor proportional to the deviation from the min and max
93 | * negociated temperatures for the shipment.
94 | */
95 | asset Contract identified by contractId {
96 | o String contractId
97 | --> Grower grower
98 | --> Shipper shipper
99 | --> Importer importer
100 | o DateTime arrivalDateTime
101 | o Double unitPrice
102 | o Double minTemperature
103 | o Double maxTemperature
104 | o Double minPenaltyFactor
105 | o Double maxPenaltyFactor
106 | }
107 |
108 | /**
109 | * A concept for a simple street address
110 | */
111 | concept Address {
112 | o String city optional
113 | o String country
114 | o String street optional
115 | o String zip optional
116 | }
117 |
118 | /**
119 | * An abstract participant type in this business network
120 | */
121 | abstract participant Business identified by email {
122 | o String email
123 | o Address address
124 | o Double accountBalance
125 | }
126 |
127 | /**
128 | * A Grower is a type of participant in the network
129 | */
130 | participant Grower extends Business {
131 | }
132 |
133 | /**
134 | * A Shipper is a type of participant in the network
135 | */
136 | participant Shipper extends Business {
137 | }
138 |
139 | /**
140 | * An Importer is a type of participant in the network
141 | */
142 | participant Importer extends Business {
143 | }
144 |
145 | /**
146 | * JUST FOR INITIALIZING A DEMO
147 | */
148 | transaction SetupDemo {
149 | }
150 |
151 | /**
152 | * An event - when the temperature goes outside the agreed-upon boundaries
153 | */
154 | event TemperatureThresholdEvent {
155 | o String message
156 | o Double temperature
157 | --> Shipment shipment
158 | }
159 |
160 | /**
161 | * An event - when the ship arrives at the port
162 | */
163 | event ShipmentInPortEvent {
164 | o String message
165 | --> Shipment shipment
166 | }
167 |
--------------------------------------------------------------------------------
/NcaaMarchMadness/src/main/java/com/makotojava/ncaabb/sqlgenerator/TournamentParticipantSqlGenerator.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2017 Makoto Consulting Group, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.makotojava.ncaabb.sqlgenerator;
17 |
18 | import java.io.BufferedReader;
19 | import java.io.BufferedWriter;
20 | import java.io.File;
21 | import java.io.FileReader;
22 | import java.io.FileWriter;
23 | import java.io.IOException;
24 |
25 | import org.apache.commons.lang3.StringUtils;
26 | import org.apache.log4j.Logger;
27 |
28 | import com.opencsv.CSVReader;
29 |
30 | public class TournamentParticipantSqlGenerator extends SqlGenerator {
31 |
32 | private static final Logger log = Logger.getLogger(TournamentParticipantSqlGenerator.class);
33 |
34 | private Integer year;
35 |
36 | private Integer getYear() {
37 | if (year == null) {
38 | throw new RuntimeException("Configuration Error: Year not found: cannot continue!");
39 | }
40 | return year;
41 | }
42 |
43 | private void setYear(Integer year) {
44 | this.year = year;
45 | }
46 |
47 | public TournamentParticipantSqlGenerator(String outputDirectory, String year) {
48 | super(outputDirectory);
49 | setYear(Integer.valueOf(year));
50 | }
51 |
52 | public static void main(String[] args) {
53 | // Read the specified file from arg[0]
54 | String filename = (args.length > 0) ? args[0] : StringUtils.EMPTY;
55 | String year = (args.length > 1) ? args[1] : StringUtils.EMPTY;
56 |
57 | if (StringUtils.isEmpty(filename) || StringUtils.isEmpty(year)) {
58 | throw new IllegalArgumentException("Bad syntax. Usage:\n\t" + SqlGenerator.class.getSimpleName() + " filename");
59 | }
60 |
61 | File inputFile = new File(filename);
62 | try (CSVReader csvReader = new CSVReader(new BufferedReader(new FileReader(inputFile)))) {
63 | // Read the file and generate SQL from it
64 | String outputDirectory = StringUtils.left(inputFile.getPath(),
65 | StringUtils.lastIndexOf(inputFile.getPath(), File.separatorChar));
66 | TournamentParticipantSqlGenerator sqlGenerator = new TournamentParticipantSqlGenerator(outputDirectory, year);
67 | sqlGenerator.processFile(csvReader);
68 | csvReader.close();
69 | log.info("Done.");
70 | } catch (IOException e) {
71 | log.error("IOException occurred while reading the input file => " + inputFile, e);
72 | }
73 | }
74 |
75 | @Override
76 | protected boolean isProbablyData(String[] line) {
77 | return line != null && line.length > 0 && StringUtils.isNotBlank(line[0]);
78 | }
79 |
80 | @Override
81 | protected String fetchStatCat(String[] line) {
82 | return TournamentParticipant.STATCAT_TOURNAMENT_PARTICIPANT;
83 | }
84 |
85 | @Override
86 | protected String fetchYear(String[] line) {
87 | return getYear().toString();
88 | }
89 |
90 | @Override
91 | protected boolean isStatCategoryHeader(String[] line) {
92 | return true;
93 | }
94 |
95 | @Override
96 | protected void writeOutputFile(String year, String sql) {
97 | File outputFile = new File(
98 | getOutputDirectory() + File.separatorChar + "load_tournament_participants-" + getYear().toString() + ".sql");
99 | try (BufferedWriter bufferedWriter = new BufferedWriter(new FileWriter(outputFile))) {
100 | bufferedWriter.write(sql);
101 | bufferedWriter.close();
102 | } catch (IOException e) {
103 | log.error(
104 | "IOException occurred while writing output file => " + getOutputDirectory() + File.separatorChar
105 | + outputFile.getName());
106 | ;
107 | }
108 |
109 | }
110 |
111 | }
112 |
--------------------------------------------------------------------------------
/NcaaMarchMadness/src/test/java/com/makotojava/ncaabb/dao/TournamentAnalyticsJdbcDaoTest.java:
--------------------------------------------------------------------------------
1 | package com.makotojava.ncaabb.dao;
2 |
3 | import static org.junit.jupiter.api.Assertions.assertAll;
4 | import static org.junit.jupiter.api.Assertions.assertEquals;
5 | import static org.junit.jupiter.api.Assertions.assertNotNull;
6 |
7 | import org.junit.jupiter.api.BeforeEach;
8 | import org.junit.jupiter.api.DisplayName;
9 | import org.junit.jupiter.api.Test;
10 | import org.junit.platform.runner.JUnitPlatform;
11 | import org.junit.runner.RunWith;
12 | import org.springframework.context.ApplicationContext;
13 | import org.springframework.context.annotation.AnnotationConfigApplicationContext;
14 |
15 | import com.makotojava.ncaabb.model.TournamentAnalytics;
16 | import com.makotojava.ncaabb.springconfig.ApplicationConfig;
17 |
18 | @RunWith(JUnitPlatform.class)
19 | public class TournamentAnalyticsJdbcDaoTest {
20 |
21 | private ApplicationContext applicationContext;
22 | private TournamentAnalyticsDao classUnderTest;
23 |
24 | @BeforeEach
25 | public void setUp() throws Exception {
26 | applicationContext = new AnnotationConfigApplicationContext(ApplicationConfig.class);
27 | classUnderTest = applicationContext.getBean(TournamentAnalyticsDao.class);
28 | }
29 |
30 | @Test
31 | @DisplayName("Testing fetchByYear()")
32 | public void fetchByYear() {
33 |
34 | assertAll(
35 | () -> {
36 | Integer year = 2010;
37 |
38 | TournamentAnalytics tournamentAnalytics = classUnderTest.fetchByYear(year);
39 | assertNotNull(tournamentAnalytics);
40 | assertEquals(Integer.valueOf(44), tournamentAnalytics.getMinScore());
41 | assertEquals(Integer.valueOf(101), tournamentAnalytics.getMaxScore());
42 | },
43 | () -> {
44 | Integer year = 2011;
45 | TournamentAnalytics tournamentAnalytics = classUnderTest.fetchByYear(year);
46 | assertNotNull(tournamentAnalytics);
47 | assertEquals(Integer.valueOf(41), tournamentAnalytics.getMinScore());
48 | assertEquals(Integer.valueOf(102), tournamentAnalytics.getMaxScore());
49 | },
50 | () -> {
51 | Integer year = 2012;
52 |
53 | TournamentAnalytics tournamentAnalytics = classUnderTest.fetchByYear(year);
54 | assertNotNull(tournamentAnalytics);
55 | assertEquals(Integer.valueOf(41), tournamentAnalytics.getMinScore());
56 | assertEquals(Integer.valueOf(102), tournamentAnalytics.getMaxScore());
57 | },
58 | () -> {
59 | Integer year = 2013;
60 |
61 | TournamentAnalytics tournamentAnalytics = classUnderTest.fetchByYear(year);
62 | assertNotNull(tournamentAnalytics);
63 | assertEquals(Integer.valueOf(34), tournamentAnalytics.getMinScore());
64 | assertEquals(Integer.valueOf(95), tournamentAnalytics.getMaxScore());
65 | },
66 | () -> {
67 | Integer year = 2014;
68 |
69 | TournamentAnalytics tournamentAnalytics = classUnderTest.fetchByYear(year);
70 | assertNotNull(tournamentAnalytics);
71 | assertEquals(Integer.valueOf(35), tournamentAnalytics.getMinScore());
72 | assertEquals(Integer.valueOf(93), tournamentAnalytics.getMaxScore());
73 | },
74 | () -> {
75 | Integer year = 2015;
76 |
77 | TournamentAnalytics tournamentAnalytics = classUnderTest.fetchByYear(year);
78 | assertNotNull(tournamentAnalytics);
79 | assertEquals(Integer.valueOf(39), tournamentAnalytics.getMinScore());
80 | assertEquals(Integer.valueOf(94), tournamentAnalytics.getMaxScore());
81 | },
82 | () -> {
83 | Integer year = 2016;
84 |
85 | TournamentAnalytics tournamentAnalytics = classUnderTest.fetchByYear(year);
86 | assertNotNull(tournamentAnalytics);
87 | assertEquals(Integer.valueOf(43), tournamentAnalytics.getMinScore());
88 | assertEquals(Integer.valueOf(105), tournamentAnalytics.getMaxScore());
89 | },
90 | () -> {
91 | Integer year = 2017;
92 |
93 | TournamentAnalytics tournamentAnalytics = classUnderTest.fetchByYear(year);
94 | assertNotNull(tournamentAnalytics);
95 | assertEquals(Integer.valueOf(39), tournamentAnalytics.getMinScore());
96 | assertEquals(Integer.valueOf(103), tournamentAnalytics.getMaxScore());
97 | });
98 | }
99 |
100 | }
101 |
--------------------------------------------------------------------------------
/perishable-network/networkimage.svg:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/iot-perishable-network/networkimage.svg:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/iot-perishable-network-advanced/networkimage.svg:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/NcaaMarchMadness/.classpath:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
--------------------------------------------------------------------------------
/iot-perishable-network-advanced/permissions.acl:
--------------------------------------------------------------------------------
1 | /**
2 | * System and Network Admin access rules
3 | */
4 | rule SystemACL {
5 | description: "System ACL to permit all access"
6 | participant: "org.hyperledger.composer.system.Participant"
7 | operation: ALL
8 | resource: "org.hyperledger.composer.system.**"
9 | action: ALLOW
10 | }
11 |
12 | rule NetworkAdminUser {
13 | description: "Grant business network administrators full access to user resources"
14 | participant: "org.hyperledger.composer.system.NetworkAdmin"
15 | operation: ALL
16 | resource: "**"
17 | action: ALLOW
18 | }
19 |
20 | /**
21 | * Rules for Participant registry access
22 | */
23 | rule Grower_R_Grower {
24 | description: "Grant Growers access to Grower resources"
25 | participant: "org.acme.shipping.perishable.Grower"
26 | operation: READ
27 | resource: "org.acme.shipping.perishable.Grower"
28 | action: ALLOW
29 | }
30 |
31 | rule Shipper_R_Shipper {
32 | description: "Grant Shippers access to Shipper resources"
33 | participant: "org.acme.shipping.perishable.Shipper"
34 | operation: READ
35 | resource: "org.acme.shipping.perishable.Shipper"
36 | action: ALLOW
37 | }
38 |
39 | rule Importer_RU_Importer {
40 | description: "Grant Importers access to Importer resources"
41 | participant: "org.acme.shipping.perishable.Importer"
42 | operation: READ,UPDATE
43 | resource: "org.acme.shipping.perishable.Importer"
44 | action: ALLOW
45 | }
46 |
47 | rule Importer_RU_Grower {
48 | description: "Grant Importers access to Grower participant"
49 | participant: "org.acme.shipping.perishable.Importer"
50 | operation: READ,UPDATE
51 | resource: "org.acme.shipping.perishable.Grower"
52 | action: ALLOW
53 | }
54 |
55 | /**
56 | * Rules for Asset registry access
57 | */
58 | rule ALL_RU_Shipment {
59 | description: "Grant All Participants in org.acme.shipping.perishable namespace READ/UPDATE access to Shipment assets"
60 | participant: "org.acme.shipping.perishable.*"
61 | operation: READ,UPDATE
62 | resource: "org.acme.shipping.perishable.Shipment"
63 | action: ALLOW
64 | }
65 |
66 | rule ALL_RU_Contract {
67 | description: "Grant All Participants in org.acme.shipping.perishable namespace READ/UPDATE access to Contract assets"
68 | participant: "org.acme.shipping.perishable.*"
69 | operation: READ,UPDATE
70 | resource: "org.acme.shipping.perishable.Contract"
71 | action: ALLOW
72 | }
73 |
74 | /**
75 | * Rules for Transaction invocations
76 | */
77 | rule Grower_C_ShipmentPacked {
78 | description: "Grant Growers access to invoke ShipmentPacked transaction"
79 | participant: "org.acme.shipping.perishable.Grower"
80 | operation: CREATE
81 | resource: "org.acme.shipping.perishable.ShipmentPacked"
82 | action: ALLOW
83 | }
84 |
85 | rule Shipper_C_ShipmentPickup {
86 | description: "Grant Shippers access to invoke ShipmentPickup transaction"
87 | participant: "org.acme.shipping.perishable.Shipper"
88 | operation: CREATE
89 | resource: "org.acme.shipping.perishable.ShipmentPickup"
90 | action: ALLOW
91 | }
92 |
93 | rule Shipper_C_ShipmentLoaded {
94 | description: "Grant Shippers access to invoke ShipmentLoaded transaction"
95 | participant: "org.acme.shipping.perishable.Shipper"
96 | operation: CREATE
97 | resource: "org.acme.shipping.perishable.ShipmentLoaded"
98 | action: ALLOW
99 | }
100 |
101 | rule GpsSensor_C_GpsReading {
102 | description: "Grant IoT GPS Sensor devices full access to the appropriate transactions"
103 | participant: "org.acme.shipping.perishable.GpsSensor"
104 | operation: CREATE
105 | resource: "org.acme.shipping.perishable.GpsReading"
106 | action: ALLOW
107 | }
108 |
109 | rule TemperatureSensor_C_TemperatureReading {
110 | description: "Grant IoT Temperature Sensor devices full access to the appropriate transactions"
111 | participant: "org.acme.shipping.perishable.TemperatureSensor"
112 | operation: CREATE
113 | resource: "org.acme.shipping.perishable.TemperatureReading"
114 | action: ALLOW
115 | }
116 |
117 | rule Importer_C_ShipmentReceived {
118 | description: "Grant Importers access to invoke the ShipmentReceived transaction"
119 | participant: "org.acme.shipping.perishable.Importer"
120 | operation: CREATE
121 | resource: "org.acme.shipping.perishable.ShipmentReceived"
122 | action: ALLOW
123 | }
124 |
125 | /**
126 | * Make sure all resources are locked down by default.
127 | * If permissions need to be granted to certain resources, that should happen
128 | * above this rule. Anything not explicitly specified gets locked down.
129 | */
130 | rule Default {
131 | description: "Deny all participants access to all resources"
132 | participant: "ANY"
133 | operation: ALL
134 | resource: "org.acme.shipping.perishable.*"
135 | action: DENY
136 | }
137 |
--------------------------------------------------------------------------------