Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
Suggestible
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
open-source
Suggestible
Commits
44794538
Commit
44794538
authored
7 months ago
by
Phil Höfer
Browse files
Options
Downloads
Patches
Plain Diff
Segregate Query Answering
parent
3d63553a
No related branches found
No related tags found
No related merge requests found
Pipeline
#10072
passed
7 months ago
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/main.rs
+17
-13
17 additions, 13 deletions
src/main.rs
with
17 additions
and
13 deletions
src/main.rs
+
17
−
13
View file @
44794538
...
...
@@ -8,6 +8,7 @@ use std::io::{self, BufRead, BufReader};
use
std
::
error
::
Error
;
use
std
::
str
::
FromStr
;
use
std
::
fs
;
use
std
::
time
::
SystemTime
;
use
importers
::
Importer
;
use
importers
::
file
::
FileImporter
;
...
...
@@ -69,7 +70,7 @@ fn main() -> Result<(), io::Error> {
}
// data locations: vec!["../../data/data.csv","data/data.csv","data.csv","data_full.csv"]
markov_chain
=
read_from_db
(
config
.clone
(),
markov_chain
);
read_from_db
(
config
.clone
(),
&
mut
markov_chain
);
// let term_frequency_threshold = match config.get("term_frequency_threshold") {
// Some(toml::Value::Integer(n)) if *n >= 0 => *n as usize,
...
...
@@ -92,7 +93,14 @@ fn main() -> Result<(), io::Error> {
let
server
=
Server
::
http
(
"0.0.0.0:8000"
)
.unwrap
();
for
request
in
server
.incoming_requests
()
{
// println!("received request! method: {:?}, url: {:?}, headers: {:?}",
process_request
(
request
,
config
.clone
(),
&
mut
markov_chain
,
last_update
)
}
Ok
(())
}
fn
process_request
(
request
:
tiny_http
::
Request
,
config
:
HashMap
<
String
,
String
>
,
markov_chain
:
&
mut
CompositePredictor
,
mut
last_update
:
SystemTime
)
{
// println!("received request! method: {:?}, url: {:?}, headers: {:?}",
// request.method(),
// request.url(),
// request.headers()
...
...
@@ -110,7 +118,7 @@ fn main() -> Result<(), io::Error> {
if
client_auth
!=
server_auth
.clone
()
{
println!
(
"invalid auth:{}, server auth: {}"
,
client_auth
,
server_auth
);
request
.respond
(
Response
::
from_string
(
""
));
continue
;
return
;
}
},
_
=>
{}
...
...
@@ -133,7 +141,7 @@ fn main() -> Result<(), io::Error> {
let
elapsed
=
now
.duration_since
(
last_update
)
.expect
(
"Time went backwards"
);
if
elapsed
>=
std
::
time
::
Duration
::
from_secs
(
24
*
60
*
60
)
{
markov_chain
.decay
();
markov_chain
=
read_from_db
(
config
.clone
(),
markov_chain
);
read_from_db
(
config
.clone
(),
markov_chain
);
last_update
=
now
;
}
},
...
...
@@ -141,13 +149,9 @@ fn main() -> Result<(), io::Error> {
//println!("Error: {}",e);
}
}
}
Ok
(())
}
fn
read_from_db
(
config
:
HashMap
<
String
,
String
>
,
mut
predictor
:
CompositePredictor
)
->
CompositePredictor
{
fn
read_from_db
(
config
:
HashMap
<
String
,
String
>
,
predictor
:
&
mut
CompositePredictor
)
{
let
mut
raw_list
=
String
::
new
();
let
blocklist
:
Vec
<&
str
>
=
match
config
.get
(
"blocklist"
)
{
...
...
@@ -180,23 +184,23 @@ fn read_from_db(config: HashMap<String, String>, mut predictor: CompositePredict
count
+=
1
;
}
println!
(
"{} queries read from DB"
,
count
);
predictor
},
Err
(
e
)
=>
{
println!
(
"Error while reading from DB: {}"
,
e
);
predictor
}
}
},
Err
(
e
)
=>
{
println!
(
"Error while connecting to DB: {}"
,
e
);
predictor
}
}
},
_
=>
{
println!
(
"No DB config found. Skipping..."
);
predictor
}
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment