display services availability rates
This commit is contained in:
parent
1990c4ecd3
commit
4601c09f32
|
@ -0,0 +1,2 @@
|
|||
ALTER TABLE "services" DROP "availability_ipv6";
|
||||
ALTER TABLE "services" DROP "availability_ipv4";
|
|
@ -0,0 +1,2 @@
|
|||
ALTER TABLE "services" ADD COLUMN "availability_ipv6" TEXT NOT NULL DEFAULT "";
|
||||
ALTER TABLE "services" ADD COLUMN "availability_ipv4" TEXT NOT NULL DEFAULT "";
|
|
@ -69,6 +69,8 @@ pub async fn check(url: &str, ipv: Option<u8>) -> Result<Services, String> {
|
|||
}.to_string(),
|
||||
ipv6: "".to_string(),
|
||||
ipv4: "".to_string(),
|
||||
availability_ipv6: "".to_string(),
|
||||
availability_ipv4: "".to_string(),
|
||||
})
|
||||
}
|
||||
Err(e) => Err(e.to_string()),
|
||||
|
|
|
@ -92,6 +92,8 @@ async fn add_installation_post(submission: Form<Strict<Submission<'_>>>) -> Temp
|
|||
server: service.server,
|
||||
ipv6: "".to_string(),
|
||||
ipv4: "".to_string(),
|
||||
availability_ipv6: "".to_string(),
|
||||
availability_ipv4: "".to_string(),
|
||||
})
|
||||
.execute(connection)
|
||||
.unwrap();
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
use diesel::prelude::*;
|
||||
use rocket_dyn_templates::serde::Serialize;
|
||||
|
||||
#[derive(Queryable, Selectable, Insertable, Serialize)]
|
||||
#[derive(Queryable, Selectable, Insertable, Serialize, Debug)]
|
||||
#[diesel(table_name = crate::schema::services)]
|
||||
#[diesel(check_for_backend(diesel::sqlite::Sqlite))]
|
||||
pub struct Services {
|
||||
|
@ -10,9 +10,11 @@ pub struct Services {
|
|||
pub server: String,
|
||||
pub ipv6: String,
|
||||
pub ipv4: String,
|
||||
pub availability_ipv6: String,
|
||||
pub availability_ipv4: String,
|
||||
}
|
||||
|
||||
#[derive(Queryable, Selectable, Insertable, Serialize)]
|
||||
#[derive(Queryable, Selectable, Insertable, Serialize, Debug)]
|
||||
#[diesel(table_name = crate::schema::scans)]
|
||||
#[diesel(check_for_backend(diesel::sqlite::Sqlite))]
|
||||
pub struct Scans {
|
||||
|
|
|
@ -17,6 +17,8 @@ diesel::table! {
|
|||
server -> Text,
|
||||
ipv6 -> Text,
|
||||
ipv4 -> Text,
|
||||
availability_ipv6 -> Text,
|
||||
availability_ipv4 -> Text,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -5,6 +5,7 @@ use ::services::establish_connection;
|
|||
use ::services::models::Scans;
|
||||
use ::services::models::Services;
|
||||
use ::services::schema::scans::dsl::scans;
|
||||
use ::services::schema::scans::installation;
|
||||
use ::services::schema::services::dsl::*;
|
||||
use diesel::associations::HasTable;
|
||||
use diesel::ExpressionMethods;
|
||||
|
@ -47,6 +48,24 @@ async fn main() {
|
|||
.execute(connection)
|
||||
.unwrap();
|
||||
|
||||
let installation_scans = scans
|
||||
.filter(installation.eq(service.url.to_string()))
|
||||
.limit(100)
|
||||
.select(Scans::as_select())
|
||||
.load(connection)
|
||||
.unwrap();
|
||||
|
||||
let ipv6_successes = installation_scans
|
||||
.iter()
|
||||
.filter(|s| s.result_ipv6 == "ok")
|
||||
.count();
|
||||
let ipv4_successes = installation_scans
|
||||
.iter()
|
||||
.filter(|s| s.result_ipv4 == "ok")
|
||||
.count();
|
||||
|
||||
let scans_nb = installation_scans.len();
|
||||
|
||||
if let Ok(service_new) = check(&service.url, None).await {
|
||||
diesel::update(services.find(&service.url))
|
||||
.set((
|
||||
|
@ -55,6 +74,12 @@ async fn main() {
|
|||
server.eq(&service_new.server),
|
||||
ipv6.eq(&result_ipv6),
|
||||
ipv4.eq(&result_ipv4),
|
||||
availability_ipv6
|
||||
.eq(((ipv6_successes as f32 / scans_nb as f32 * 100.0) as u8)
|
||||
.to_string()),
|
||||
availability_ipv4
|
||||
.eq(((ipv4_successes as f32 / scans_nb as f32 * 100.0) as u8)
|
||||
.to_string()),
|
||||
))
|
||||
.execute(connection)
|
||||
.unwrap();
|
||||
|
|
|
@ -14,6 +14,8 @@
|
|||
<th>Server</th>
|
||||
<th>IPv6</th>
|
||||
<th>IPv4</th>
|
||||
<th>IPv6 availability</th>
|
||||
<th>IPv4 availability</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
|
@ -24,6 +26,8 @@
|
|||
<td>{{ service.server }}</td>
|
||||
<td>{% if service.ipv6 == "ok" %}✓{% else %}—{% endif %}</td>
|
||||
<td>{% if service.ipv4 == "ok" %}✓{% else %}—{% endif %}</td>
|
||||
<td>{% if service.ipv6 == "" %}—{% else %}{{ service.availability_ipv6 }} %{% endif %}</td>
|
||||
<td>{% if service.ipv4 == "" %}—{% else %}{{ service.availability_ipv4 }} %{% endif %}</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
|
|
Loading…
Reference in New Issue