-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: added topstories analysis, UI components, created analyzer func…
…tions [past 4h limit]
- Loading branch information
TheFullResolution
committed
Apr 1, 2017
1 parent
57af093
commit e30f4a8
Showing
14 changed files
with
259 additions
and
95 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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 |
---|---|---|
@@ -1,5 +1,7 @@ | ||
@import "../shared"; | ||
@import "../variables" | ||
@import "../variables"; | ||
|
||
.content { | ||
composes: commonContent; | ||
text-align: center; | ||
} |
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,15 @@ | ||
|
||
.top10 { | ||
list-style-position: inside; | ||
display: flex; | ||
justify-content: center; | ||
ol { | ||
padding: 0; | ||
list-style-type:decimal-leading-zero; | ||
li { | ||
margin: 10px 0; | ||
} | ||
} | ||
margin: 20px 0; | ||
text-align: left; | ||
} |
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
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,34 @@ | ||
import { ListFetch } from 'Analyzer/functions/firebase'; | ||
import { GetTitlesList } from 'Analyzer/functions/processors'; | ||
import { GetTopTenWords } from 'Analyzer/functions/textparsers'; | ||
import { OPTION4 } from 'Page2/Page2Text'; | ||
|
||
function Option4Analysis() { | ||
return new Promise(function(resolve, reject) { | ||
ListFetch('topstories') | ||
.then(list => { | ||
GetTitlesList(list).then(newlist => { | ||
const top10 = GetTopTenWords(newlist); | ||
resolve(top10); | ||
}); | ||
}) | ||
.catch(error => { | ||
reject(error); | ||
}); | ||
}); | ||
} | ||
|
||
export function Analyzer(value) { | ||
return new Promise(function(resolve) { | ||
var top10; | ||
switch (value) { | ||
case OPTION4: | ||
top10 = Option4Analysis(); | ||
break; | ||
default: | ||
top10 = []; | ||
} | ||
|
||
resolve(top10); | ||
}); | ||
} |
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
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,47 @@ | ||
import moment from 'moment'; | ||
import { ItemFetch } from './firebase'; | ||
|
||
export function GetTitlesList(list) { | ||
return new Promise(function(resolve, reject) { | ||
const titeledPromises = list.map(item => { | ||
return ItemFetch(item).then( | ||
result => { | ||
return result.title; | ||
}, | ||
error => { | ||
return error.message; | ||
} | ||
); | ||
}); | ||
Promise.all(titeledPromises) | ||
.then(function(results) { | ||
resolve(results); | ||
}) | ||
.catch(reason => { | ||
reject(reason); | ||
}); | ||
}); | ||
} | ||
|
||
|
||
|
||
export function GetThisWeekList(list) { | ||
return new Promise(function(resolve) { | ||
const filteredPromises = list.map(item => { | ||
return ItemFetch(item).then(result => { | ||
return { | ||
time: result.time, | ||
title: result.title | ||
}; | ||
}); | ||
}); | ||
Promise.all(filteredPromises).then(function(results) { | ||
const weekAgo = moment().subtract(7, 'days'); | ||
|
||
const filtered = results.filter(item => { | ||
return weekAgo.isBefore(moment.unix(item.time)); | ||
}); | ||
resolve(filtered); | ||
}); | ||
}); | ||
} |
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,45 @@ | ||
function TransformToWords(list) { | ||
return list | ||
.reduce( | ||
(result, item) => { | ||
return result.concat(item.match(/\b[^\d\W]+\b/g)); | ||
}, | ||
[] | ||
) | ||
.map(item => { | ||
return item.toLowerCase(); | ||
}) | ||
.filter(item => { | ||
return item.length > 1; | ||
}); | ||
} | ||
|
||
function SummorizeWords(list) { | ||
const wordsAndCountObj = list.reduce( | ||
(result, item) => { | ||
result[item] = result[item] || { | ||
word: item, | ||
count: 0 | ||
}; | ||
result[item].count += 1; | ||
|
||
return result; | ||
}, | ||
{} | ||
); | ||
|
||
return Object.keys(wordsAndCountObj) | ||
.map(function(key) { | ||
return wordsAndCountObj[key]; | ||
}) | ||
.sort(function(a, b) { | ||
return b.count - a.count; | ||
}); | ||
} | ||
|
||
export function GetTopTenWords(list) { | ||
const transformedList = TransformToWords(list); | ||
const uniqueList = SummorizeWords(transformedList); | ||
const top10 = uniqueList.slice(0, 10); | ||
return top10; | ||
} |
This file was deleted.
Oops, something went wrong.
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
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
Oops, something went wrong.