statistics.cc
Go to the documentation of this file.
1 // =======================================================
2 //
3 // sqlite statistics
4 //
5 // =======================================================
6 
8 
9 #include "sqlite3.h"
10 
11 #include <cmath>
12 
13 using namespace std::string_literals;
14 
15 double
17  std::string const& table_name,
18  std::string const& column_name)
19 {
21  r << select("avg(" + column_name + ")").from(db, table_name);
22  return unique_value(r);
23 }
24 
25 double
27  std::string const& table_name,
28  std::string const& column_name)
29 {
30  auto r = query<double>(
31  db,
32  "select avg("s + column_name + ")" + " from (select " + column_name +
33  " from " + table_name + " order by " + column_name +
34  " limit 2 - (select count(*) from " + table_name + ") % 2" +
35  " offset (select (count(*) - 1) / 2" + " from " + table_name + "))");
36  return unique_value(r);
37 }
38 
39 double
41  std::string const& table_name,
42  std::string const& column_name)
43 {
44  auto r = query<double>(db,
45  "select sum("s + "(" + column_name + "-(select avg(" +
46  column_name + ") from " + table_name + "))" + "*" +
47  "(" + column_name + "-(select avg(" + column_name +
48  ") from " + table_name + "))" + " ) /" + "(count(" +
49  column_name + ")) from " + table_name);
50  return std::sqrt(unique_value(r));
51 }
T unique_value(query_result< T > const &r)
Definition: query_result.h:94
double rms(sqlite3 *db, std::string const &table_name, std::string const &column_name)
Definition: statistics.cc:40
std::string string
Definition: nybbler.cc:12
auto select(T const &...t)
Definition: select.h:146
struct sqlite3 sqlite3
double mean(sqlite3 *db, std::string const &table_name, std::string const &column_name)
Definition: statistics.cc:16
static QCString * s
Definition: config.cpp:1042
double median(sqlite3 *db, std::string const &table_name, std::string const &column_name)
Definition: statistics.cc:26