cloud or not cloud

Re: cloud or not cloud

Postby Otto » Fri Nov 15, 2024 9:04 am

...

Certainly, you remember the HTML report generator.
I can now enter another query for this evaluation:
Can you create an HTML table for me from the statistics?

I can then integrate the HTML into the existing report generator. Here's a first preview:

viewtopic.php?f=3&t=42879&p=257998&hilit=html+report&sid=345879a060539062e1ebd96331640625#p257998

Image
********************************************************************
mod harbour - Vamos a la conquista de la Web
modharbour.org
https://www.facebook.com/groups/modharbour.club
********************************************************************
User avatar
Otto
 
Posts: 6332
Joined: Fri Oct 07, 2005 7:07 pm

Re: cloud or not cloud

Postby Otto » Fri Nov 15, 2024 9:19 am

...

The next prompt for automation would be:

Can you now make this table dynamic, read the data from JSON files, and create a pie chart for the age structure?

Then, depending on the JSON, the database used could be replaced, etc.

Image
********************************************************************
mod harbour - Vamos a la conquista de la Web
modharbour.org
https://www.facebook.com/groups/modharbour.club
********************************************************************
User avatar
Otto
 
Posts: 6332
Joined: Fri Oct 07, 2005 7:07 pm

Re: cloud or not cloud

Postby Otto » Fri Nov 15, 2024 9:50 am

...

Please note that we did nothing except send the DBF table to the AI with a request for statistical analysis, and now we have the program.

I didn't program a single line of the whole program manually!

By the way, this PHP4DBF library largely uses FIVEWIN/HARBOUR syntax.





The next prompt is now the one where you automatically create a data.json from the DBF file, which is then displayed.


Here, I use my own development: the php4dbf library.
The prompt:
Can you provide me with source code to directly create the data.json using php4dbf?

Here the json from sourcecode:

Code: Select all  Expand view

{
    "records": 500,
    "ageStatistics": [
        {
            "ageGroup": "20-29",
            "count": 54
        },
        {
            "ageGroup": "30-39",
            "count": 53
        },
        {
            "ageGroup": "40-49",
            "count": 60
        },
        {
            "ageGroup": "50-59",
            "count": 63
        },
        {
            "ageGroup": "60-69",
            "count": 62
        },
        {
            "ageGroup": "70-79",
            "count": 64
        },
        {
            "ageGroup": "80-89",
            "count": 69
        },
        {
            "ageGroup": "90-99",
            "count": 75
        }
    ],
    "salaryStatistics": [
        {
            "range": "Under \u20ac25,000",
            "count": 79
        },
        {
            "range": "\u20ac25,000 - \u20ac50,000",
            "count": 82
        },
        {
            "range": "\u20ac50,001 - \u20ac75,000",
            "count": 68
        },
        {
            "range": "\u20ac75,001 - \u20ac100,000",
            "count": 97
        },
        {
            "range": "Over \u20ac100,000",
            "count": 174
        }
    ],
    "stateDistribution": [
        {
            "state": "IL",
            "count": 13
        },
        {
            "state": "MA",
            "count": 7
        },
        {
            "state": "WY",
            "count": 10
        },
        {
            "state": "ID",
            "count": 12
        },
        {
            "state": "CT",
            "count": 9
        },
        {
            "state": "WV",
            "count": 10
        },
        {
            "state": "RI",
            "count": 9
        },
        {
            "state": "HI",
            "count": 14
        },
        {
            "state": "AK",
            "count": 10
        },
        {
            "state": "IN",
            "count": 15
        },
        {
            "state": "WA",
            "count": 13
        },
        {
            "state": "NC",
            "count": 10
        },
        {
            "state": "AR",
            "count": 15
        },
        {
            "state": "MS",
            "count": 10
        },
        {
            "state": "VT",
            "count": 11
        },
        {
            "state": "NY",
            "count": 13
        },
        {
            "state": "KY",
            "count": 13
        },
        {
            "state": "LA",
            "count": 14
        },
        {
            "state": "VA",
            "count": 5
        },
        {
            "state": "DE",
            "count": 13
        },
        {
            "state": "WI",
            "count": 11
        },
        {
            "state": "FL",
            "count": 10
        },
        {
            "state": "TN",
            "count": 8
        },
        {
            "state": "KS",
            "count": 8
        },
        {
            "state": "PA",
            "count": 9
        },
        {
            "state": "CA",
            "count": 13
        },
        {
            "state": "IA",
            "count": 10
        },
        {
            "state": "ME",
            "count": 7
        },
        {
            "state": "OH",
            "count": 8
        },
        {
            "state": "NH",
            "count": 13
        },
        {
            "state": "MI",
            "count": 6
        },
        {
            "state": "OK",
            "count": 13
        },
        {
            "state": "NM",
            "count": 8
        },
        {
            "state": "SC",
            "count": 11
        },
        {
            "state": "CO",
            "count": 7
        },
        {
            "state": "MT",
            "count": 10
        },
        {
            "state": "AZ",
            "count": 8
        },
        {
            "state": "NE",
            "count": 16
        },
        {
            "state": "TX",
            "count": 7
        },
        {
            "state": "AL",
            "count": 7
        },
        {
            "state": "MN",
            "count": 8
        },
        {
            "state": "NV",
            "count": 9
        },
        {
            "state": "ND",
            "count": 6
        },
        {
            "state": "MD",
            "count": 8
        },
        {
            "state": "UT",
            "count": 9
        },
        {
            "state": "NJ",
            "count": 11
        },
        {
            "state": "OR",
            "count": 9
        },
        {
            "state": "SD",
            "count": 11
        },
        {
            "state": "GA",
            "count": 10
        },
        {
            "state": "MO",
            "count": 3
        }
    ],
    "maritalStatus": [
        {
            "status": "Married (T)",
            "count": 255
        },
        {
            "status": "Not Married (F)",
            "count": 245
        }
    ]
}
 



And here is the working source code.

Code: Select all  Expand view

<?php

// Include the php4dbf library
include 'php4dbf.php';

// Path to the DBF file
$dbfFilePath = 'data.dbf'; // Change this to the path of your DBF file

// Open the DBF file
$dbfHandle = php4dbf_openDbf($dbfFilePath);
if (!$dbfHandle) {
    die("Error: Unable to open DBF file.");
}

// Get the number of records and fields
$totalRecords = php4dbf_numrecords($dbfHandle);
$totalFields = php4dbf_numfields($dbfHandle);

// Initialize statistics
$ageGroups = [
    '20-29' => 0, '30-39' => 0, '40-49' => 0,
    '50-59' => 0, '60-69' => 0, '70-79' => 0,
    '80-89' => 0, '90-99' => 0,
];
$salaryRanges = [
    'Under €25,000' => 0, '€25,000 - €50,000' => 0,
    '€50,001 - €75,000' => 0, '€75,001 - €100,000' => 0,
    'Over €100,000' => 0,
];
$states = [];
$maritalStatus = ['T' => 0, 'F' => 0];

// Loop through each record
for ($i = 1; $i <= $totalRecords; $i++) {
    $record = php4dbf_get_record_with_names($dbfHandle, $i);
    if (!$record) {
        continue; // Skip if the record is invalid
    }

    // Age Statistics
    $age = isset($record['AGE']) ? (int)$record['AGE'] : 0;
    if ($age >= 20 && $age <= 29) $ageGroups['20-29']++;
    elseif ($age >= 30 && $age <= 39) $ageGroups['30-39']++;
    elseif ($age >= 40 && $age <= 49) $ageGroups['40-49']++;
    elseif ($age >= 50 && $age <= 59) $ageGroups['50-59']++;
    elseif ($age >= 60 && $age <= 69) $ageGroups['60-69']++;
    elseif ($age >= 70 && $age <= 79) $ageGroups['70-79']++;
    elseif ($age >= 80 && $age <= 89) $ageGroups['80-89']++;
    elseif ($age >= 90) $ageGroups['90-99']++;

    // Salary Statistics
    $salary = isset($record['SALARY']) ? (float)$record['SALARY'] : 0;
    if ($salary < 25000) $salaryRanges['Under €25,000']++;
    elseif ($salary <= 50000) $salaryRanges['€25,000 - €50,000']++;
    elseif ($salary <= 75000) $salaryRanges['€50,001 - €75,000']++;
    elseif ($salary <= 100000) $salaryRanges['€75,001 - €100,000']++;
    else $salaryRanges['Over €100,000']++;

    // State Distribution
    $state = isset($record['STATE']) ? $record['STATE'] : 'Unknown';
    if (!isset($states[$state])) {
        $states[$state] = 0;
    }
    $states[$state]++;

    // Marital Status
    $marital = isset($record['MARRIED']) ? $record['MARRIED'] : 'F';
    if (isset($maritalStatus[$marital])) {
        $maritalStatus[$marital]++;
    }
}

// Close the DBF file
php4dbf_close($dbfHandle);

// Prepare JSON data
$jsonData = [
    'records' => $totalRecords,
    'ageStatistics' => array_map(function ($group, $count) {
        return ['ageGroup' => $group, 'count' => $count];
    }, array_keys($ageGroups), $ageGroups),
    'salaryStatistics' => array_map(function ($range, $count) {
        return ['range' => $range, 'count' => $count];
    }, array_keys($salaryRanges), $salaryRanges),
    'stateDistribution' => array_map(function ($state, $count) {
        return ['state' => $state, 'count' => $count];
    }, array_keys($states), $states),
    'maritalStatus' => [
        ['status' => 'Married (T)', 'count' => $maritalStatus['T']],
        ['status' => 'Not Married (F)', 'count' => $maritalStatus['F']],
    ],
];

// Write JSON data to a file
file_put_contents('data.json', json_encode($jsonData, JSON_PRETTY_PRINT));

echo "JSON file has been created successfully: data.json";


 




**
* php4dbf Library
*
* This library provides functions to interact with DBF (dBASE) files using PHP.
* It includes functions for opening DBF files, reading headers and field descriptions,
* properly padding values, and adding records to DBF files.
*
* Functions:
* - php4dbf_logline: Logs messages to a log file.
* - php4dbf_openDbf: Opens a DBF file.
* - php4dbf_eof: Determines the end of the file (EOF) based on the number of records in the currently open DBF file.
* - php4dbf_DBUse: Reads all necessary information from a DBF file at once and returns it.
* - php4dbf_getDbfHeader: Retrieves the header of a DBF file.
* - php4dbf_getFieldDescriptors: Retrieves the field descriptions of a DBF file.
* - php4dbf_padValue: Properly pads values based on their type.
* - php4dbf_addRecordToDbf: Adds records to a DBF file.
* - php4dbf_calculateRecordLength: Calculates the record length based on field descriptors.
* - php4dbf_updateRecord: Updates a record in a DBF file.
* - php4dbf_deleteRecord: Deletes a record in a DBF file.
* - php4dbf_createDbf: Creates a new DBF file.
* - php4dbf_compareDbfFiles: Compares two DBF files.
* - php4dbf_getRecordByIndex: Retrieves a record by its index.
* - php4dbf_numrecords: Retrieves the number of records in a DBF file.
* - php4dbf_numfields: Retrieves the number of fields in a DBF file.
* - php4dbf_get_record_with_names: Retrieves a record with field names from a DBF file.
* - php4dbf_close: Closes a DBF file.
* - php4dbf_loadAllFile: Loads the entire DBF file into memory.
* - php4dbf_loadAllHeader: Extracts header information from the file content string.
* - php4dbf_readHeader: Reads header information from a file pointer.
* - php4dbf_extractFields: Extracts field descriptions from the loaded DBF file data.
* - php4dbf_readRecordByIndex: Reads a record based on the specified index.
* - php4dbf_closeDbfFile: Closes an open DBF file handle, if present.
* - php4dbf_openFile: Opens a DBF file and loads either the full content or just the header.
* - php4dbf_getLastUpdateDate: Extracts the last update date from the DBF header.
* - php4dbf_flock: Attempts to create a lock and lock file.
* - php4dbf_phpunlock: Releases the lock created by `flock` using PHP.
* - php4dbf_unlock: Releases the custom lock by deleting lock files.
* - php4dbf_updateField: Updates a specific field within a record in a DBF file.
* - php4dbf_updateLastModifiedDate: Updates the last modified date in the DBF header.
* - php4dbf_checkFileSizeConsistency: Checks file size consistency with the number of records.
* - php4dbf_appendBlank: Adds a blank record to a DBF file.
* - php4dbf_getHeader: Helper function for common header processing.
* - php4dbf_DBUse: Opens a DBF file and reads the header as well as the field descriptions.
* - FieldPos: Returns the 1-based position of a field by its name.
* - FieldName: Returns the name of a field by its 1-based position.
* - FieldPosLast: Returns the 1-based position of the last field.
* - php4dbf_dbGoTop: Moves the record pointer to the first valid record.
* - php4dbf_dbGoTo: Moves the record pointer to a specific record.
* - php4dbf_init: Initializes the DBF file for reading.
* - php4dbf_get_next_record: Reads the next record from the DBF file.
* - php4dbf_parse_record: Parses a record from raw binary data into an associative array.
* - php4dbf_convert_value: Converts a raw binary value to the appropriate data type based on field type.
*/

********************************************************************
mod harbour - Vamos a la conquista de la Web
modharbour.org
https://www.facebook.com/groups/modharbour.club
********************************************************************
User avatar
Otto
 
Posts: 6332
Joined: Fri Oct 07, 2005 7:07 pm

Re: cloud or not cloud

Postby Carles » Sat Nov 16, 2024 6:30 am

Good morning,

I'm sorry Otto, but I'm not convinced. The question here (I understand) is whether to program with Harbour in the cloud or not. My answer is a resounding yes. Everything else, about dbf, ai, ... has nothing to do with what was asked.

And it is curious that you mention the use of PHP to be able to manage Dbf on the Internet. You force a user to know Apache and PHP perfectly for this, that is, overload them with even more knowledge to be able to manage a Dbf en internet. Is that really the case, Otto?

I think this way they will never make the change to the web...

C.
Salutacions, saludos, regards

"...programar es fácil, hacer programas es difícil..."

UT Page -> https://carles9000.github.io/
Forum UT -> https://discord.gg/bq8a9yGMWh
Skype -> https://join.skype.com/cnzQg3Kr1dnk
User avatar
Carles
 
Posts: 1137
Joined: Fri Feb 10, 2006 2:34 pm
Location: Barcelona

Re: cloud or not cloud

Postby Otto » Sat Nov 16, 2024 8:15 am

Dear Carles,

> I think this way they will never make the change to the web...

Yes, it is as you say.

With Mod Harbour, we have a deployment problem that we haven’t been able to solve.
We should have invested more effort from the start to become part of a distribution like XAMPP.

Additionally, we shouldn’t have split up the Mod Harbour group in the beginning. While the V2 development might be technically very good, what’s missing is a company like Fivetech to stand behind it. A developer invests so much time—especially in a small company—that continuity must be ensured, as much as possible.

As it stands, deploying servers is very difficult. Larger companies won’t allow the use of the Mod Harbour server, and for smaller users, it’s too complex.
In reality, it’s actually quite simple, but it requires admin rights.
As I’ve already mentioned, the core issue is the user base.

Best regards,
Otto
********************************************************************
mod harbour - Vamos a la conquista de la Web
modharbour.org
https://www.facebook.com/groups/modharbour.club
********************************************************************
User avatar
Otto
 
Posts: 6332
Joined: Fri Oct 07, 2005 7:07 pm

Previous

Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: Google [Bot] and 58 guests