-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
pang
committed
Aug 20, 2019
1 parent
e6470b4
commit 44ea967
Showing
116 changed files
with
9,430 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
# Cyclops Estimation & Forecasting Engine Dashboard | ||
|
||
GUI dashboard for the Cyclops Estimation and Forecasting engine. | ||
|
||
## Prerequisites | ||
``` | ||
pip install -r requirements.txt | ||
``` | ||
## Start-up | ||
|
||
- Start Cyclops as normal | ||
- Set up `conf.ini` with the parameters necessary to interact with your | ||
Cyclops instance | ||
- Start the dashboard's back-end: | ||
``` | ||
python app.py | ||
``` | ||
- Start the dashboard itself: | ||
``` | ||
cd dashboard | ||
npm install | ||
npm run dev | ||
``` | ||
- After the first time you do not need to run `npm install` | ||
|
||
## Usage | ||
- Use the **Forecasting** page to generate forecasts | ||
- Use the **Rule Management** page to add or remove rules | ||
|
||
## Caution | ||
It is recommended to use a separate Cyclops instance with a snapshot | ||
of your real usage data to avoid cluttering your real database with fake records | ||
or losing real data when performing a forecast cleanup. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
from flask import Flask, request, json, jsonify | ||
import client | ||
from flask_cors import CORS | ||
|
||
|
||
app = Flask(__name__) | ||
CORS(app) | ||
|
||
|
||
@app.route('/addrule', methods=['POST']) | ||
def addrule(): | ||
data = json.loads(request.data) | ||
client.addrulestring(data['target'], data['rule']) | ||
return jsonify(data['rule']) | ||
|
||
|
||
@app.route('/removerule', methods=['POST']) | ||
def removerule(): | ||
data = json.loads(request.data) | ||
count = client.removerule(data['target'], data['rule']) | ||
return jsonify(count) | ||
|
||
|
||
@app.route('/listcdrrules', methods=['GET']) | ||
def listcdrrules(): | ||
return jsonify(client.listcdrrules()) | ||
|
||
|
||
@app.route('/listbillrules', methods=['GET']) | ||
def listbillrules(): | ||
return jsonify(client.listbillrules()) | ||
|
||
|
||
@app.route('/bills', methods=['GET']) | ||
def getbills(): | ||
return jsonify(client.listbills()) | ||
|
||
|
||
@app.route('/accounts', methods=['GET']) | ||
def getaccounts(): | ||
return jsonify(client.listaccounts()) | ||
|
||
|
||
@app.route('/cleanup', methods=['POST']) | ||
def cleanup(): | ||
data = json.loads(request.data) | ||
cleanup_dict = client.cleanup(data['target'], data['rules']) | ||
return jsonify(cleanup_dict) | ||
|
||
|
||
@app.route('/singleforecast', methods=['POST']) | ||
def singleforecast(): | ||
data = json.loads(request.data) | ||
forecast = client.generatesingleforecast(data['account'], data['target'], data['size']) | ||
return jsonify(forecast) | ||
|
||
|
||
@app.route('/globalforecast', methods=['POST']) | ||
def globalforecast(): | ||
data = json.loads(request.data) | ||
forecast = client.generateglobalforecast(data['target'], data['size']) | ||
return jsonify(forecast) | ||
|
||
|
||
@app.route('/patternforecast', methods=['POST']) | ||
def patternforecast(): | ||
data = json.loads(request.data) | ||
forecast = client.generatepatternforecast(data['target'], data['size']) | ||
return jsonify(forecast) | ||
|
||
|
||
if __name__ == '__main__': | ||
app.run() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
import requests | ||
import time | ||
import settings | ||
import dbaccess | ||
|
||
|
||
settings = settings.Settings('conf.ini') | ||
dbaccess = dbaccess.DBAccess(settings) | ||
|
||
|
||
def addrule(target, path): | ||
with open(path, 'r') as file: | ||
rule = file.read() | ||
if target == 'cdr': | ||
r = requests.post(settings.cdrRuleEndpoint, data=rule) | ||
print(r.status_code) | ||
elif target == 'bill': | ||
r = requests.post(settings.billRuleEndpoint, data=rule) | ||
print(r.status_code) | ||
print(rule) | ||
return rule | ||
|
||
|
||
def listbills(): | ||
r = requests.get(settings.billEndpoint) | ||
return r.json() | ||
|
||
|
||
def listaccounts(): | ||
return dbaccess.printaccounts() | ||
|
||
|
||
def listcdrrules(): | ||
return dbaccess.printcdrrules() | ||
|
||
|
||
def listbillrules(): | ||
return dbaccess.printbillrules() | ||
|
||
|
||
def addrulestring(target, string): | ||
if target == 'cdr': | ||
r = requests.post(settings.cdrRuleEndpoint, data=string) | ||
print(r.status_code) | ||
elif target == 'bill': | ||
r = requests.post(settings.billRuleEndpoint, data=string) | ||
print(r.status_code) | ||
print(string) | ||
return string | ||
|
||
|
||
def removerule(target, rule): | ||
if target == 'cdr': | ||
db = settings.cdrdb | ||
elif target == 'bill': | ||
db = settings.billdb | ||
return dbaccess.deleterule(db, rule) | ||
|
||
|
||
def generatesingleforecast(account, target, size): | ||
r = requests.post(settings.forecastEndpoint, json={"command": "Forecast", | ||
"account": account, | ||
"target": target, | ||
"forecastSize": size}) | ||
print(r.status_code) | ||
time.sleep(1) | ||
return dbaccess.printbill(target) | ||
|
||
|
||
def generateglobalforecast(target, size): | ||
r = requests.post(settings.forecastEndpoint, json={"command": "Forecast", | ||
"target": target, | ||
"forecastSize": size}) | ||
print(r.status_code) | ||
time.sleep(1) | ||
return dbaccess.printbill(target) | ||
|
||
|
||
def generatepatternforecast(target, size): | ||
r = requests.post(settings.forecastEndpoint, json={"command": "GlobalForecast", | ||
"target": target, | ||
"forecastSize": size}) | ||
print(r.status_code) | ||
time.sleep(1) | ||
return dbaccess.printbill(target) | ||
|
||
|
||
def cleanup(target, rules): | ||
cdr_rules = 0 | ||
bill_rules = 0 | ||
if rules: | ||
cdr_rules = dbaccess.deleterule(settings.cdrdb, "%{}%".format(target)) | ||
bill_rules = dbaccess.deleterule(settings.billdb, "%{}%".format(target)) | ||
usages = dbaccess.deleteusage("%{}%".format(target)) | ||
udrs = dbaccess.deleteudr("%{}%".format(target)) | ||
cdrs = dbaccess.deletecdr("%{}%".format(target)) | ||
bills = dbaccess.deletebill("%{}%".format(target)) | ||
return {"cdr_rules": cdr_rules, "Bill_rules": bill_rules, "usages": usages, "udrs": udrs, "cdrs": cdrs, | ||
"bills": bills} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
[ENDPOINTS] | ||
cdrRuleEndpoint = http://localhost:4570/rule | ||
billRuleEndpoint = http://hocalhost:4571/rule | ||
udrEndpoint = http://localhost:4567/command | ||
billEndpoint = http://localhost:4569/bill | ||
|
||
[DB] | ||
user = cyclops | ||
password = pass1234 | ||
host = localhost | ||
port = 5432 | ||
cyclops_udr = cyclops_udr | ||
cyclops_cdr = cyclops_cdr | ||
cyclops_billing = cyclops_billing |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
> 1% | ||
last 2 versions | ||
not ie <= 8 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
module.exports = { | ||
root: true, | ||
env: { | ||
node: true | ||
}, | ||
extends: ["plugin:vue/essential", "@vue/prettier"], | ||
rules: { | ||
"no-console": process.env.NODE_ENV === "production" ? "error" : "off", | ||
"no-debugger": process.env.NODE_ENV === "production" ? "error" : "off" | ||
}, | ||
parserOptions: { | ||
parser: "babel-eslint" | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
node_modules/ | ||
package-lock.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"esversion": 6 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
# Change Log | ||
|
||
## [1.2.1] 2019-06-14 | ||
### Dependencies Updates, Vue Material Update | ||
- Updated all out of date dependencies from `package.json` file | ||
- The framework `Vuematerial.io` was updated to the latest beta version `1.0.0-beta-11` | ||
|
||
## [1.2.0] 2019-04-30 | ||
### Dependencies Updates | ||
- Updated all out of date dependencies from `package.json` file | ||
|
||
## [1.1.0] 2019-02-08 | ||
### Dependencies Updates, Improvements | ||
- Updated all out of date dependencies from `package.json` file | ||
- Removed all `to=""` and replaced with `href=""` props from non router-link components for avoid this error `[Vue warn]: Error in render: "TypeError: Cannot read property 'options' of undefined"` | ||
- Changed links from footer | ||
|
||
## [1.0.3] 2018-11-26 | ||
### Bug Fixing | ||
- Fixed error `[Vue warn]: Error in render: "TypeError: Cannot read property 'options' of undefined"` | ||
|
||
## [1.0.2] 2018-11-19 | ||
### Plugin Updates, BugFixing | ||
- Updated all `dependencies` and `devDependencies` to the latest versions | ||
- Cleaned `package.json` file | ||
- Removed all lint warnings and errors | ||
- Github issues fixed | ||
- Other bug fixes | ||
|
||
## [1.0.1] 2018-07-13 | ||
### BugFixing and Updates | ||
- updated all the npm packages | ||
- scroll issue on mobile devices fixed | ||
- added button `Upgrade to PRO` in the sidebar | ||
- another small bug fixes | ||
|
||
## [1.0.0] 2018-05-03 | ||
- Initial Release |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<!-- | ||
IMPORTANT: Please use the following link to create a new issue: | ||
https://www.creative-tim.com/new-issue/vue-material-dashboard | ||
**If your issue was not created using the app above, it will be closed immediately.** | ||
--> | ||
|
||
<!-- | ||
Love Creative Tim? Do you need Angular, React, Vuejs or HTML? You can visit: | ||
👉 https://www.creative-tim.com/bundles | ||
👉 https://www.creative-tim.com | ||
--> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2018 Creative Tim | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
Oops, something went wrong.