Package: quantcast-cli
Quantcast CLIFor convenience, read theDocumentation.IntroductionQuantcast CLI, accessible via thectopcommand, is designed to analyze cookie log files and identify the most active cookie on a specified date. It processes files containing cookie IDs along with their corresponding timestamps, and outputs the most frequently encountered cookie ID for a given day.InstallationTo install Quantcast CLI, use pip by running the following command in your terminal:$pipinstallquantcast_cli---> 100%installedMake sure Python and pip are installed on your system before executing the above command.UsageThectopcommand requires a log file in CSV format with each record comprising a cookie ID and a timestamp. It accepts the following main arguments:-for--file: Specifies the path to the cookie log file. The default value iscookie_log.csv.-dor--date: Sets the target date for which to find the most active cookie, formatted asYYYY-MM-DD. The default date is2018-12-09.Command Syntax$ctop--helpUsage: ctop [OPTIONS]╭─ Options ───────────────────────────────────────────────────────────────────────────────────────────╮│ --file                -f      PATH          Cookies file path [default: cookie_log.csv]             ││ --date                -d      [%Y-%m-%d]    Targeted date in UTC format [default: 2018-12-09]       ││ --install-completion                        Install completion for the current shell.               ││ --show-completion                           Show completion for the current shell.                  ││ --help                                      Show this message and exit.                             │╰─────────────────────────────────────────────────────────────────────────────────────────────────────╯ExampleTo find the most active cookie on December 9, 2018, from a file namedcookie_log.csv, use:$ctop-fcookie_log.csv-d2018-12-09AtY0laUfhglK3lC7This command outputs the cookie ID(s) with the highest number of occurrences on the specified date to stdout.Options--install-completion: Installs shell completion for the current shell.--show-completion: Displays the completion setup script for the current shell, allowing you to copy or customize its installation.--help: Shows the help message, detailing all available options.Running with DockerFor users who prefer Docker or wish to run the Quantcast CLI tool in a containerized environment, we have provided a Docker image. This method simplifies the execution process and ensures compatibility across different environments.PrerequisitesDocker must be installed on your system. For installation instructions, refer to theofficial Docker documentation.UsageTo run the Quantcast CLI tool using Docker, you can use the following command structure:$dockerrun-it--rm-v/cookie_log.csv:/file.csv\itismoej/ctop-f/file.csv-dYYYY-MM-DDsome-cookie-keyReplace/cookie_log.csvwith the full path to your cookie log file on your host machine,/file.csvwith the path and file name you want to use inside the container, andYYYY-MM-DDwith the target date you're interested in.ExampleIf you have a cookie log file namedcookie_log.csvlocated in/homeon your machine, and you want to find the most active cookie forDecember 9, 2018, the command would look like this:$dockerrun-it--rm-v/home/cookie_log.csv:/cookie_log.csv\itismoej/ctop-f/cookie_log.csv-d2018-12-09AtY0laUfhglK3lC7This command mounts thecookie_log.csvfile from your host into the Docker container and executes the ctop command inside the container to process the file. The-itflag is used to run the container interactively, and--rmensures that the container is removed after execution to prevent accumulation of unused containers.NotesEnsure that the volume mapping (-vflag) correctly reflects the path to your cookie log file on your host and the desired path within the container.The Docker imageitismoej/ctopis the official image for running the Quantcast CLI tool. Make sure to pull the latest version if you haven't done so recently.Using Docker to run the Quantcast CLI tool provides a seamless and environment-independent way to analyze your cookie log files, eliminating the need for local Python environment setup.File FormatYour cookie log file must adhere to the following structure:cookie,timestampHere, each line should contain a cookie ID, followed by its timestamp in the ISO 8601 format (YYYY-MM-DDTHH:MM:SS+00:00), separated by a comma andsorted by timestamps in reverse order.Sample Log Filecookie,timestamp
AtY0laUfhglK3lC7,2018-12-09T14:19:00+00:00
SAZuXPGUrfbcn5UA,2018-12-09T10:13:00+00:00
...PerformanceThe Quantcast CLI tool is optimized for high performance, capable of processing extensive datasets with efficiency. Below are the key performance optimizations that enable the tool to handle millions of records swiftly:Multi-processing with MapReduceQuantcast CLI employs a multi-processing strategy, enhanced by the MapReduce programming model, to leverage the computing power of modern multi-core processors effectively. This approach allows the tool to parallelize the data processing workload across multiple cores, significantly reducing the overall processing time. The MapReduce model splits the processing task into two main phases: the Map phase, where the dataset is divided into smaller chunks that are processed in parallel, and the Reduce phase, where the results of these parallel processes are combined into a final output. This method is particularly effective for analyzing extensive log files, enabling the tool to process 8 million records in just 5 seconds on a computer with 4 CPU cores.Binary Search on Sorted TimestampsThe tool assumes that timestamps in the cookie log file are sorted. This assumption allows for the use of a binary search algorithm when filtering records by the specified date. This efficiency gain is crucial when dealing with large datasets, as it minimizes the time required to locate and filter records by date.LicenceThis project is licensed under the terms of the MIT license.