From 3b28e47efe18f71d43f8dca6ac25463ae5ca92a6 Mon Sep 17 00:00:00 2001
From: Giga <52905881+giga-a@users.noreply.github.com>
Date: Thu, 16 Sep 2021 14:31:42 -0700
Subject: [PATCH] [auto-b] Added finding ages option (req) - ref 38d56f839602
---
app.js | 37 +++++++++++++++++-----------
modules/string-analysis.js | 50 +++++++++++++++++++++++++++++++++++++-
public/app.html | 48 +++++++++++++++++++++++++++++-------
3 files changed, 111 insertions(+), 24 deletions(-)
diff --git a/app.js b/app.js
index ddd7896..4756237 100755
--- a/app.js
+++ b/app.js
@@ -258,6 +258,7 @@ app.post('/analyze_string', async function (req, res, next) {
unknown: [],
maybe: []
}
+ let ages = []
let names_origins = []
const words_info = []
const temp_words = []
@@ -421,6 +422,12 @@ app.post('/analyze_string', async function (req, res, next) {
await stringAnalysis.find_numbers(req, all_words)
helper.log_to_file_queue(req.body.uuid, '[Done] Finding Numbers')
}
+ if (req.body.option.includes('FindAges')) {
+ helper.log_to_file_queue(req.body.uuid, '[Starting] Finding Ages')
+ ages = await stringAnalysis.guess_age_from_string(req)
+ helper.log_to_file_queue(req.body.uuid, '[Done] Finding Ages')
+ }
+
req.body.string = req.body.string.toLowerCase()
if (req.body.option.includes('ConvertNumbers')) {
@@ -491,26 +498,28 @@ app.post('/analyze_string', async function (req, res, next) {
helper.log_to_file_queue(req.body.uuid, '[Finished] Analyzing: ' + req.body.string + ' Task: ' + req.body.uuid)
/*fs.writeFileSync('./test.json', JSON.stringify({
- username: username,
- uuid: temp_uuid,
- info,
- table: all_words,
- common: temp_words,
- words_info: words_info,
- user_info_normal: user_info_normal,
- user_info_advanced: user_info_advanced,
- user_info_special: user_info_special,
- names_origins: names_origins,
- custom_search: custom_search,
- graph: graph,
- stats: stats_default,
- logs: logs
+ username: username,
+ uuid: temp_uuid,
+ info,
+ ages: ages,
+ table: all_words,
+ common: temp_words,
+ words_info: words_info,
+ user_info_normal: user_info_normal,
+ user_info_advanced: user_info_advanced,
+ user_info_special: user_info_special,
+ names_origins: names_origins,
+ custom_search: custom_search,
+ graph: graph,
+ stats: stats_default,
+ logs: logs
}, null, 2) , 'utf-8');*/
res.json({
username: username,
uuid: temp_uuid,
info,
+ ages: ages,
table: all_words,
common: temp_words,
words_info: words_info,
diff --git a/modules/string-analysis.js b/modules/string-analysis.js
index 600eef7..a6f62bd 100755
--- a/modules/string-analysis.js
+++ b/modules/string-analysis.js
@@ -225,6 +225,53 @@ async function get_maybe_words (req, all_words) {
}).filter(word => word.length > 1)
}
+async function guess_age_from_string(req) {
+ let results = []
+
+ try {
+ let age_4_numbers = /\d{4}|\d{2}/g
+ let current_year = new Date().getFullYear()
+ while ((match = age_4_numbers.exec(req.body.string)) != null) {
+ let temp_dict = {"found":"","year":"","age":""}
+ let found = 0
+ let year = 0
+ let age = 0
+ temp_dict.found = match[0]
+ found = parseInt(match[0])
+ if (found >= 50 && found <= 99){
+ year = found + 1900
+ age = current_year - year
+ if (age <= 75){
+ temp_dict.year = year.toString()
+ temp_dict.age = age.toString()
+ }
+ }
+ if (found >= 14 && found <= 49){
+ year = current_year - found
+ age = found
+ if (age <= 75){
+ temp_dict.year = year.toString()
+ temp_dict.age = age.toString()
+ }
+ }
+ if (found >= 1950){
+ year = found
+ age = current_year - year
+ if (age <= 75){
+ temp_dict.year = year.toString()
+ temp_dict.age = age.toString()
+ }
+ }
+
+ results.push(temp_dict)
+ }
+
+ } catch (err) {
+ }
+
+ return results
+}
+
module.exports = {
get_maybe_words,
find_symbols,
@@ -235,5 +282,6 @@ module.exports = {
split_alphabet_case,
most_common,
find_other,
- analyze_string
+ analyze_string,
+ guess_age_from_string
}
diff --git a/public/app.html b/public/app.html
index d1034fb..9fb9f6a 100755
--- a/public/app.html
+++ b/public/app.html
@@ -261,6 +261,7 @@
#words-info-section,
#stats-section,
#metadata-section,
+ #ages-section,
#custom-search-section,
#names-origins-section {
display: none;
@@ -805,6 +806,21 @@
+
+