Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pre alpha live charts #32

Merged
merged 6 commits into from
Feb 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
node_modules/
.DS_Store
*.py
*.py
test.js
2 changes: 1 addition & 1 deletion cli/mrcli-backup.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import chalk from 'chalk'
import FilesystemOperators from '../src/cli/filesystem.js'
import ArchivePackage from '../src/cli/archive.js'
import WizardUtils from '../src/cli/commonWizard.js'
import serverOperations from '../src/cli/common.js'
import {serverOperations} from '../src/cli/common.js'

import * as fs from 'fs'

Expand Down
27 changes: 15 additions & 12 deletions cli/mrcli-company.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,36 +89,39 @@ if (myArgs.report) {
// Obtain the competitors
let competitors = []
let competitiveInteractions = []
const competitorIds = Object.keys(comp_results[0].comparison)
for (const comp in competitorIds) {
const competitor = competitorIds[comp]
const [compSuccess, compStat, myCompetitor] = await companyCtl.findById(competitor)
const competitorIdxs = Object.keys(comp_results[0].comparison)
for (const compIdx in competitorIdxs) {
// const competitor = competitorIds[comp]
// console.log(comp_results[0].comparison[competitor].name)
const competitorIndex = competitorIdxs[compIdx] // Index in the comparison property for the company
const competitorName = comp_results[0].comparison[competitorIndex].name // Actual company name
const [compSuccess, compStat, myCompetitor] = await companyCtl.findByName(competitorName)
const [mostSuccess, mostStat, myMost] = await interactionCtl.findByName(
comp_results[0].comparison[competitor].most_similar.name
comp_results[0].comparison[competitorIndex].most_similar.name
)
const [leastSuccess, leastStat, myLeast] = await interactionCtl.findByName(
comp_results[0].comparison[competitor].least_similar.name
comp_results[0].comparison[competitorIndex].least_similar.name
)
// Format the scores and names
const leastScore = String(
comp_results[0].comparison[competitor].least_similar.score.toFixed(2) * 100
Math.round(comp_results[0].comparison[competitorIndex].least_similar.score * 100)
) + '%'
const mostScore = String(
comp_results[0].comparison[competitor].most_similar.score.toFixed(2) * 100
Math.round(comp_results[0].comparison[competitorIndex].most_similar.score * 100)
) + '%'
const leastName = comp_results[0].comparison[competitor].least_similar.name.slice(0,40) + '...'
const mostName = comp_results[0].comparison[competitor].most_similar.name.slice(0,40) + '...'
const leastName = comp_results[0].comparison[competitorIndex].least_similar.name.slice(0,40) + '...'
const mostName = comp_results[0].comparison[competitorIndex].most_similar.name.slice(0,40) + '...'
competitors.push(
{
company: myCompetitor[0],
mostSimilar: {
score: mostScore,
name: comp_results[0].comparison[competitor].most_similar.name,
name: comp_results[0].comparison[competitorIndex].most_similar.name,
interaction: myMost[0]
},
leastSimilar: {
score: leastScore,
name: comp_results[0].comparison[competitor].least_similar.name,
name: comp_results[0].comparison[competitorIndex].least_similar.name,
interaction: myLeast[0]
}
}
Expand Down
2 changes: 1 addition & 1 deletion cli/mrcli-interaction.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import Environmentals from '../src/cli/env.js'
import s3Utilities from '../src/cli/s3.js'
import CLIOutput from '../src/cli/output.js'
import FilesystemOperators from '../src/cli/filesystem.js'
import serverOperations from '../src/cli/common.js'
import {serverOperations} from '../src/cli/common.js'
import ArchivePackage from '../src/cli/archive.js'

// External modules
Expand Down
9 changes: 6 additions & 3 deletions cli/mrcli-setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,16 +53,19 @@ function parseCLIArgs() {
function getEnv () {
return {
DEFAULT: {
rest_servers: ["http://cherokee.from-ca.com:16767", "http://cherokee.from-ca.com:26767", "http://cherokee.from-ca.com:46767"],
// rest_servers: ["http://cherokee.from-ca.com:16767", "http://cherokee.from-ca.com:26767", "http://cherokee.from-ca.com:46767"],
rest_servers: ["http://cherokee.from-ca.com:16767", "http://cherokee.from-ca.com:46767"],
user: "rflores", // For now we're not going to prompt for this it is a placeholder
secret: "password", // For now we're not going to prompt for this it is a placeholder
api_key: "Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VybmFtZSI6InJmbG9yZXMiLCJjb21wYW55IjoieCIsImlhdCI6MTY1NTAwNDM2NH0.znocDyjS4VSS9tu_ND-pUKw76yNgseUUHYpJ1Tq87do",
working_dir: "/tmp",
company_dns_servers: {
"http://cherokee.from-ca.com:16767": "http://cherokee.from-ca.com:16868",
"http://cherokee.from-ca.com:26767": "http://cherokee.from-ca.com:26868",
//"http://cherokee.from-ca.com:26767": "http://cherokee.from-ca.com:26868",
"http://cherokee.from-ca.com:46767": "http://cherokee.from-ca.com:46868"
}
},
theme: "coffee",
echarts_server: "http://cherokee.from-ca.com:3000"
},
s3_settings: {
user: "medium_roast_io",
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 19 additions & 4 deletions src/cli/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { Auth, Companies, Interactions, Studies } from '../api/mrServer.js'
import axios from 'axios'
import * as fs from 'fs'
import * as path from 'path'
import * as http from 'http'
import FilesystemOperators from './filesystem.js'

class serverOperations {
Expand Down Expand Up @@ -121,13 +122,27 @@ class Utilities {
* @param {String} dir - the target directory to save the file to
* @param {String} filename - the name of the file to save the image to
*/
async downloadImage(url, directory, filename) {
async downloadImage(url, directory, filename, showDownloadStatus=false) {
const myFullPath = path.resolve(directory, filename)
const myConfig = {
responseType: 'stream'
responseType: "stream",
}
// const myFilesystem = new FilesystemOperators()
// const fileResp = myFilesystem.saveTextFile(myFullPath, "")
try {
const resp = await axios.get(url, myConfig)
const imageFile = fs.createWriteStream(myFullPath)
const myDownload = resp.data.pipe(imageFile)
await myDownload.on('finish', () => {
imageFile.close()
if(showDownloadStatus) {
console.log(`SUCCESS: Downloaded [${myFullPath}]`)
}
})
return myFullPath
} catch (err) {
console.log(`ERROR: Unable to download file due to [${err}]`)
}
const resp = await axios.get(url, myConfig)
resp.data.pipe(fs.createWriteStream(myFullPath))
}

/**
Expand Down
24 changes: 21 additions & 3 deletions src/cli/companyWizard.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import mrRest from "../api/scaffold.js"
import WizardUtils from "./commonWizard.js"
import { Utilities } from "../helpers.js"
import CLIOutput from "./output.js"
import crypto from "node:crypto"

class AddCompany {
/**
Expand Down Expand Up @@ -60,6 +61,16 @@ class AddCompany {
this.output = new CLIOutput(this.env, this.objectType)
}

_linkObj(name) {
// Hash the names
// const intHash = this.crypt.createHash('sha256', prototype.name.value).digest('hex')
const objHash = crypto.createHash('sha256', name).digest('hex')

// Create the object Link
let objLink = {}
objLink[name] = objHash
return objLink
}

async getCompany () {
let myCompany = {}
Expand Down Expand Up @@ -361,10 +372,17 @@ class AddCompany {
myCompany.topics = {}
// Comparison
myCompany.comparison = {}
// linked_x
// Quality
myCompany.quality = {}


// NOTICE in the alpha version these will no longer be needed
// Linked interactions
myCompany.linked_interactions = {}
// TODO you need to link to one or more studies
myCompany.linked_studies = {}
// Link the default study
myCompany.linked_studies = this._linkObj('Default Study')


this.cutils.printLine()
console.log(chalk.blue.bold(`Saving company ${myCompany.name} to mediumroast.io...`))
let companyResp = await this.apiController.createObj(myCompany)
Expand Down
8 changes: 4 additions & 4 deletions src/cli/env.js
Original file line number Diff line number Diff line change
Expand Up @@ -170,8 +170,7 @@ class Environmentals {
companyDNS: null,
reset: null,
experimental: null,
echartsSever: null

echartsServer: null
}

// With the cli options as the priority set up the environment for the cli
Expand All @@ -181,9 +180,10 @@ class Environmentals {
cliArgs.secret ? env.secret = cliArgs.secret : env.secret = config.get('DEFAULT', 'secret')

// Set up additional parameters from config file
env.workDir = config.get('DEFAULT', 'working_dir')
env.workDir = process.env.HOME + '/.mediumroast/' + config.get('DEFAULT', 'working_dir')
env.companyDNS = config.get('DEFAULT', 'company_dns_server')
env.echartsSever = config.get('DEFAULT', 'echarts_server')
env.echartsServer = config.get('DEFAULT', 'echarts_server')
env.theme = config.get('DEFAULT', 'theme')
env.outputDir = process.env.HOME + '/' + config.get('document_settings', 'output_dir')
env.s3Server = config.get('s3_settings', 'server')
env.s3User = config.get('s3_settings', 'user')
Expand Down
28 changes: 15 additions & 13 deletions src/cli/interactionWizard.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import WizardUtils from "./commonWizard.js"
import { Utilities } from "../helpers.js"

import CLIOutput from "./output.js"
import serverOperations from "./common.js"
import {serverOperations} from "./common.js"
import s3Utilities from "./s3.js"
import FilesystemOperators from "./filesystem.js"

Expand Down Expand Up @@ -342,7 +342,7 @@ class AddInteraction {
process.stdout.write(chalk.blue.bold(`\tUploading -> `))
console.log(chalk.blue.underline(`${fileName.slice(0, 72)}...`))
const [returnedFileName, s3Results] = await this.s3Ops.s3UploadObjs([fileName], targetBucket)
return [true, {status_code: 200, status_msg: 'successfully upladed file to storage space'},myContents]
return [true, {status_code: 200, status_msg: 'successfully upladed file to storage space'}, myContents]
} else {
myContents.url = this.defaultValue
return [false, {status_code: 503, status_msg: 'the source is not a file that can be uploaded'}, myContents]
Expand Down Expand Up @@ -453,23 +453,25 @@ class AddInteraction {
const tmpType = await this.wutils.doCheckbox(
"What kind of interaction is this?",
[
{name: 'General Notes'},
{name: 'Frequently Asked Questions'},
{name: 'White Paper'},
{name: 'Case Study'},
{name: 'General Notes'}, // Becomes general
{name: 'Frequently Asked Questions'}, // Becomes faq
{name: 'White Paper'}, // Becomes article
{name: 'Case Study'}, // Becomes article
{name: 'Public Company Filing'},
{name: 'Patent'},
{name: 'Press Release'},
{name: 'Announcement'},
{name: 'Blog Post'},
{name: 'Product Document'},
{name: 'Press Release'}, // Becomes article
{name: 'Blog Post'}, // Becomes social
{name: 'Social Media Post(s)'}, // Becomes social
{name: 'Product Document'}, // Becomes product/service
{name: 'Service Document'}, // Becomes product/service
{name: 'Transcript'},
{name: 'News Article'},
{name: 'About the company'},
{name: 'Research Paper'},
{name: 'Article'}, // Becomes article
{name: 'About the company'}, // Becomes about company
{name: 'Research Paper'}, // Becomes article
{name: 'Other'},
]
)
// TODO we need to debug other
if(tmpType[0] === 'Other') {
const typePrototype = {
type_name: {
Expand Down
1 change: 1 addition & 0 deletions src/cli/s3.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ class s3Utilities {
if(!objs[myObj]){ continue } // Skip if there is an empty entry in the Array
const myKey = objs[myObj].split('/') // split to get to the file name
const myBody = fs.createReadStream(objs[myObj]) // open and read the file
// TODO need to remove any leading or trailing spaces from the file name
const myParams = {Bucket: targetBucket, Key: myKey[myKey.length - 1], Body: myBody} // setup the key elements to talk to S3
const s3Put = await this.s3Controller.putObject(myParams).promise() // Put the object
if (!isCLI) {return [myKey[myKey.length - 1], s3Put]} // return the file name and the result of the put
Expand Down
Loading