⌈⌋ branch:  freshcode


Check-in [840066990b]

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:update to GraphQL query
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | trunk
Files: files | file ages | folders
SHA1: 840066990bda713211a6c3c70b6b2d0149a64430
User & Date: mario 2022-06-05 21:30:31
Context
2022-06-05
21:30
update to GraphQL query Leaf check-in: 840066990b user: mario tags: trunk
2021-12-26
18:13
Add fossforce, remove xyz-apps.org (dead for good?, albeit kde had a similar app store now) check-in: eecd325303 user: mario tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to cron.daily/header_stats.php.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22


23
24
















25
26















27

28
29
30
31
32
33

34
35

36
37

38

39
40





41
42
43
44
45
46
47
<?php
/**
 * title: statistics
 * description: generate statistics, visitors, projects, autoupdate, etc. for header
 * version: 0.2
 * depends:
 * category: template
 * type: cron
 * x-cron: 11 23,5,16 * * *
 *
 * Approximate weekly numbers by multiplication.
 *
 */

chdir(dirname(__DIR__)); 
include("config.php");


// get CloudFlare visitor stats
/*
v4:
$ curl -X GET "https://api.cloudflare.com/client/v4/zones/023e105f4ecef8ad9ca31a8372d0c353/analytics/dashboard?since=2015-01-01T12:23:00Z&until=2015-01-02T12:23:00Z&continuous=true" \


-H "X-Auth-Email: user@example.com" \
-H "X-Auth-Key: c2547eb745079dac9320b638f5e225cf483cc5cfdda41" \
















-H "Content-Type: application/json"
*/















$json = curl()

   ->url("https://www.cloudflare.com/api_json.html")
   ->postfields([
       "a" => "stats",
       "tkn" => CLOUDFLARE_TKN,
       "email" => CLOUDFLARE_EMAIL,
       "z" => "freshcode.club",

       "interval" => 40,
    ])

   ->exec();
$stats = json_decode($json);

#print_r($stats);

$s_visitors = intval($stats->response->result->objs[0]->trafficBreakdown->uniques->regular * 4.1);
$s_pageviews = intval($stats->response->result->objs[0]->trafficBreakdown->pageviews->regular * 8.9);






// number of projects
$s_num_proj = db("SELECT COUNT(name) AS cnt FROM (SELECT name FROM release GROUP BY name)")->cnt;

// releases
$s_num_vers = db("SELECT COUNT(name) AS cnt FROM (SELECT DISTINCT name, version FROM release WHERE version != ?)", "")->cnt;





|














<
<
|
>
>
|
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
|
<
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>

>
|
|
<
|
|
<
>
|
|
>


>

>
|
|
>
>
>
>
>







1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19


20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41

42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60

61
62

63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
<?php
/**
 * title: statistics
 * description: generate statistics, visitors, projects, autoupdate, etc. for header
 * version: 0.3
 * depends:
 * category: template
 * type: cron
 * x-cron: 11 23,5,16 * * *
 *
 * Approximate weekly numbers by multiplication.
 *
 */

chdir(dirname(__DIR__)); 
include("config.php");


// get CloudFlare visitor stats


// https://developers.cloudflare.com/analytics/graphql-api/migration-guides/zone-analytics/
$ZONE_ID = "e373b910a645ebccd6035d4b38a2fe4c";
$date = new DateTime("");
$date->sub(new DateInterval("P7D"));
$date = $date->format("Y-m-d");
$payload = <<<GRAPHQL
{
  viewer {
    zones(filter: {zoneTag: $ZONE_ID}) {
      httpRequests1dGroups(orderBy: [date_ASC], limit: 100, filter:{date_geq: "$date"}) {
        dimensions {
          date
        }
        sum {
          bytes
          cachedBytes
          cachedRequests
          countryMap {
            bytes
            requests
            threats
            clientCountryName

          }
          encryptedBytes
          encryptedRequests
          pageViews
          requests
          threats
        }
        uniq {
          uniques
        }
      }
    }
  }
}
GRAPHQL;
$json = curl()
   #->url("https://api.cloudflare.com/client/v4/user/tokens/verify")
   ->url("https://api.cloudflare.com/client/v4/graphql")
   ->httpheader([

       "X-Auth-Email: " . CLOUDFLARE_EMAIL,
       "X-Auth-Key: " . CLOUDFLARE_KEY,

       "Authorization: Bearer " . COUDFLARE_TKN2,
       "Content-Type: application/json",
   ])
   ->postfields(json_encode(["query"=>$payload]))
   ->exec();
$stats = json_decode($json);
$stats = $stats->data->viewer->zones[0]->httpRequests1dGroups;
#print_r($stats);
#exit();
$s_visitors = 0;
$s_pageviews = 0;
foreach ($stats as $ds) {
    $s_visitors += $ds->uniq->uniques;
    $s_pageviews += $ds->sum->requests;
}


// number of projects
$s_num_proj = db("SELECT COUNT(name) AS cnt FROM (SELECT name FROM release GROUP BY name)")->cnt;

// releases
$s_num_vers = db("SELECT COUNT(name) AS cnt FROM (SELECT DISTINCT name, version FROM release WHERE version != ?)", "")->cnt;