text stringlengths 1 2.12k | source dict |
|---|---|
c++, recursion, template, c++20, constrained-templates
Play with test_vectors:
Level 0:
Level 1:
Level 2:
Level 3:
2
2
2
Level 3:
2
2
2
Level 3:
2
2
2
Level 2:
Level 3:
2
2
2
Level 3:
2
2
2
Level 3:
2
2
2
Level 2:
Level 3:
2
2
2
Level 3:
2
2
2
Level 3:
2
2
2
Level 1:
Level 2:
Level 3:
2
2
2
Level 3:
2
2
2
Level 3:
2
2
2
Level 2:
Level 3:
2
2
2
Level 3:
2
2
2
Level 3:
2
2
2
Level 2:
Level 3:
2
2
2
Level 3:
2
2
2
Level 3:
2
2
2
Level 1:
Level 2:
Level 3:
2
2
2
Level 3:
2
2
2
Level 3:
2
2
2
Level 2:
Level 3:
2
2
2
Level 3:
2
2
2
Level 3:
2
2
2
Level 2:
Level 3:
2
2
2
Level 3:
2
2
2
Level 3:
2
2
2
Play with test_arrays:
Level 0:
Level 1:
Level 2:
Level 3:
2
2
2
Level 3:
2
2
2
Level 3:
2
2
2
Level 2:
Level 3:
2
2
2
Level 3:
2
2
2
Level 3:
2
2
2
Level 2:
Level 3:
2
2
2
Level 3:
2
2
2
Level 3:
2
2
2
Level 1:
Level 2:
Level 3:
2
2
2
Level 3:
2
2
2
Level 3:
2
2
2
Level 2:
Level 3:
2
2
2
Level 3:
2
2
2
Level 3:
2
2
2
Level 2:
Level 3:
2
2
2
Level 3:
2
2
2
Level 3:
2
2
2
Level 1:
Level 2:
Level 3:
2
2
2
Level 3:
2
2
2
Level 3:
2
2
2
Level 2:
Level 3:
2
2
2
Level 3:
2
2
2
Level 3:
2
2
2
Level 2:
Level 3:
2
2
2
Level 3:
2
2
2
Level 3:
2
2
2
Computation finished at Tue Aug 15 11:46:33 2023
elapsed time: 0.00124901
Godbolt link is here.
All suggestions are welcome.
The summary information: | {
"domain": "codereview.stackexchange",
"id": 44987,
"lm_label": null,
"lm_name": null,
"lm_q1_score": null,
"lm_q1q2_score": null,
"lm_q2_score": null,
"openwebmath_perplexity": null,
"openwebmath_score": null,
"tags": "c++, recursion, template, c++20, constrained-templates",
"url": null
} |
c++, recursion, template, c++20, constrained-templates
Godbolt link is here.
All suggestions are welcome.
The summary information:
Which question it is a follow-up to?
A recursive_fold_left_all Template Function Implementation in C++.
What changes has been made in the code since last question?
I am trying to implement recursive_foreach_all template function in this post.
Why a new review is being asked for?
Please review recursive_foreach_all template function implementation and all suggestions are welcome.
Answer: While this is a very reasonable looking recursive foreach function, it doesn't quite have all the same semantics as std::ranges::for_each(). In particular, the standard, non-recursive version returns the function object and an iterator. While the iterator is arguably not very useful, the function object is, at least when it is properly handled by the recursive algorithm: if you look at the example usage, you'll see that it can be used to calculate the sum of a range, with the sum being stored in the function object by value. So in order to be able to do the following:
struct Sum {
void operator()(int n) { sum += n; }
int sum {0};
};
auto test_vectors = n_dim_container_generator<std::vector, 4, int>(1, 3);
recursive_foreach_all(test_vectors, [](auto& element){ ++element; return; });
auto [i, s] = recursive_foreach_all(test_vectors, Sum());
std::cout << "Sum: " << s.sum << '\n';
You have to change your recursive version a bit. In particular, you have to pass std::ranges::for_each() a fuction object that stores f, and for each call to operator() updates its copy of f:
template<std::ranges::input_range T, class Proj = std::identity, class F>
constexpr auto recursive_foreach_all(T& inputRange, F f, Proj proj = {})
{
struct RecursiveF {
constexpr auto
operator()(T::reference value) {
f = recursive_foreach_all(value, f, proj).second;
}
F f;
Proj proj;
}; | {
"domain": "codereview.stackexchange",
"id": 44987,
"lm_label": null,
"lm_name": null,
"lm_q1_score": null,
"lm_q1q2_score": null,
"lm_q2_score": null,
"openwebmath_perplexity": null,
"openwebmath_score": null,
"tags": "c++, recursion, template, c++20, constrained-templates",
"url": null
} |
c++, recursion, template, c++20, constrained-templates
auto [i, result] = std::ranges::for_each(inputRange, RecursiveF(std::move(f), proj));
return std::make_pair(i, std::move(result.f));
}
You would have to update the terminal case as well. You might also have to think about what to do with proj: should it be moved in and out of recursive calls as well? Because that too can have state, but in my code above, that state is lost when recursive calls are made. It might be better to just create one object with the state, and pass a reference to recursive calls:
namespace impl {
template<class F, class Proj>
struct recursive_for_each_state {
F f;
Proj proj;
};
template<class T, class State>
constexpr void recursive_foreach_all(T& value, State& state) {
std::invoke(state.f, std::invoke(state.proj, value));
}
template<std::ranges::input_range T, class State>
constexpr void recursive_foreach_all(T& inputRange, State& state) {
for (auto& item: inputRange)
recursive_foreach_all(item, state);
}
}
template<class T, class Proj = std::identity, class F>
constexpr auto recursive_foreach_all(T& inputRange, F f, Proj proj = {})
{
impl::recursive_for_each_state state(std::move(f), std::move(proj));
impl::recursive_foreach_all(inputRange, state);
return std::make_pair(inputRange.end(), std::move(state.f));
}
That inputRange.end() does not work for all types of inputs. You could consider just returning state.f (like std::for_each() does).
Finally, since the standard library uses for_each as the name, consider adding the extra underscore to your name as well: recursive_for_each_all(). | {
"domain": "codereview.stackexchange",
"id": 44987,
"lm_label": null,
"lm_name": null,
"lm_q1_score": null,
"lm_q1q2_score": null,
"lm_q2_score": null,
"openwebmath_perplexity": null,
"openwebmath_score": null,
"tags": "c++, recursion, template, c++20, constrained-templates",
"url": null
} |
c++, reinventing-the-wheel, tree, binary-search-tree
Title: Binary search tree with Iterators
Question: One more BST implementation with iterators added. Did not manage to find another implementation with iterators and it is my first attempt at implementing them so thought to check on your opinion:
template<typename T, typename less_than = std::less<T>>
class BinaryTree {
public:
void insert(T&& value);
void insert(T const& value);
template<typename... Args>
void emplace_insert(Args&&... value);
bool contains(T const& value) const;
template<bool IsConst>
class iterator_base;
class iterator;
class const_iterator;
iterator begin() { return iterator(min_element(root.get())); }
iterator end() { return {}; };
const_iterator begin() const { return const_iterator(min_element(root.get())); }
const_iterator end() const { return {}; };
const_iterator cbegin() const { return const_iterator(min_element(root.get())); }
const_iterator cend() const { return {}; };
private:
struct Node {
Node(T&& value): payload(std::move(value)) {}
Node(T const& value): payload(value) {}
template<typename... Args>
requires std::constructible_from<T, Args...>
Node(std::in_place_t, Args&&... args): parent(parent), payload(std::forward<Args>(args)...) {}
T payload;
Node* parent{ nullptr };
std::unique_ptr<Node> left;
std::unique_ptr<Node> right;
};
static Node* min_element(Node* node);
bool insert_node(std::unique_ptr<Node>&& node);
std::unique_ptr<Node> root;
size_t size{ 0 };
less_than cmp_less;
}; | {
"domain": "codereview.stackexchange",
"id": 44988,
"lm_label": null,
"lm_name": null,
"lm_q1_score": null,
"lm_q1q2_score": null,
"lm_q2_score": null,
"openwebmath_perplexity": null,
"openwebmath_score": null,
"tags": "c++, reinventing-the-wheel, tree, binary-search-tree",
"url": null
} |
c++, reinventing-the-wheel, tree, binary-search-tree
template<typename T, typename less_than>
template<bool IsConst>
class BinaryTree<T, less_than>::iterator_base {
public:
using value_type = std::conditional_t<IsConst, T const, T>;
using iterator_category = std::forward_iterator_tag;
using difference_type = std::ptrdiff_t;
using pointer = T*;
using reference = T&;
iterator_base() = default;
iterator_base(Node* node) : node(node) {}
friend class BinaryTree<T, less_than>;
iterator_base& operator++();
iterator_base operator++(int);
value_type& operator*();
value_type* operator->();
bool operator==(iterator_base const& other);
bool operator!=(iterator_base const& other);
private:
Node* node{ nullptr };
};
template<typename T, typename less_than>
class BinaryTree;
template<typename T, typename less_than>
struct BinaryTree<T, less_than>::const_iterator : BinaryTree<T, less_than>::iterator_base<true> {};
template<typename T, typename less_than>
struct BinaryTree<T, less_than>::iterator : BinaryTree<T, less_than>::iterator_base<false> {};
template<typename T, typename less_than>
template<bool IsConst>
bool BinaryTree<T, less_than>::iterator_base<IsConst>::operator==(iterator_base const& other) {
return node == other.node;
}
template<typename T, typename less_than>
template<bool IsConst>
bool BinaryTree<T, less_than>::iterator_base<IsConst>::operator!=(iterator_base const& other) {
return !(*this == other);
}
template<typename T, typename less_than>
template<bool IsConst>
typename BinaryTree<T, less_than>::iterator_base<IsConst>& BinaryTree<T, less_than>::iterator_base<IsConst>::operator++() {
if (node == nullptr) {
return *this;
}
if (node->right) {
node = BinaryTree<T, less_than>::min_element(node->right.get());
}
else { | {
"domain": "codereview.stackexchange",
"id": 44988,
"lm_label": null,
"lm_name": null,
"lm_q1_score": null,
"lm_q1q2_score": null,
"lm_q2_score": null,
"openwebmath_perplexity": null,
"openwebmath_score": null,
"tags": "c++, reinventing-the-wheel, tree, binary-search-tree",
"url": null
} |
c++, reinventing-the-wheel, tree, binary-search-tree
}
else {
Node* parent{ node->parent };
while (parent != nullptr && parent->right.get() == node) {
node = parent;
parent = node->parent;
}
node = parent;
}
return *this;
}
template<typename T, typename less_than>
template<bool IsConst>
typename BinaryTree<T, less_than>::iterator_base<IsConst>::value_type& BinaryTree<T, less_than>::iterator_base<IsConst>::operator*() {
return static_cast<BinaryTree<T, less_than>::iterator_base<IsConst>::value_type&>(node->payload);
}
template<typename T, typename less_than>
template<bool IsConst>
typename BinaryTree<T, less_than>::iterator_base<IsConst>::value_type* BinaryTree<T, less_than>::iterator_base<IsConst>::operator->()
{
return static_cast<BinaryTree<T, less_than>::iterator_base<IsConst>::value_type*>(&node->payload);
}
template<typename T, typename less_than>
template<bool IsConst>
BinaryTree<T, less_than>::iterator_base<IsConst> BinaryTree<T, less_than>::iterator_base<IsConst>::operator++(int) {
iterator it{ *this };
++(*this);
return it;
}
template<typename T, typename less_than>
typename BinaryTree<T, less_than>::Node* BinaryTree<T, less_than>::min_element(BinaryTree<T, less_than>::Node* node) {
if (node == nullptr || node->left == nullptr) {
return node;
}
return BinaryTree<T, less_than>::min_element(node->left.get());
}
template<typename T, typename less_than>
template<typename... Args>
void BinaryTree<T, less_than>::emplace_insert(Args&&... value)
{
BinaryTree<T, less_than>::insert_node(std::make_unique<Node>(std::forward<Args>(value)...));
}
template<typename T, typename less_than>
void BinaryTree<T, less_than>::insert(T const& value)
{
BinaryTree<T, less_than>::insert_node(std::make_unique<Node>(value));
} | {
"domain": "codereview.stackexchange",
"id": 44988,
"lm_label": null,
"lm_name": null,
"lm_q1_score": null,
"lm_q1q2_score": null,
"lm_q2_score": null,
"openwebmath_perplexity": null,
"openwebmath_score": null,
"tags": "c++, reinventing-the-wheel, tree, binary-search-tree",
"url": null
} |
c++, reinventing-the-wheel, tree, binary-search-tree
template<typename T, typename less_than>
void BinaryTree<T, less_than>::insert(T&& value)
{
BinaryTree<T, less_than>::insert_node(std::make_unique<Node>(std::move(value)));
}
template<typename T, typename less_than>
bool BinaryTree<T, less_than>::insert_node(std::unique_ptr<Node>&& node)
{
if (!root) {
root = std::move(node);
}
else {
Node* curr = root.get();
Node* parent = nullptr;
bool addToLeft{ false };
while (curr != nullptr)
{
if (cmp_less(node->payload, curr->payload)) {
parent = curr;
curr = curr->left.get();
addToLeft = true;
}
else if (cmp_less(curr->payload, node->payload)) {
parent = curr;
curr = curr->right.get();
addToLeft = false;
}
else {
return false;
}
}
node->parent = parent;
if (addToLeft) {
parent->left = move(node);
}
else {
parent->right = move(node);
}
}
return false;
}
template<typename T, typename less_than>
bool BinaryTree<T, less_than>::contains(T const& value) const {
Node* curr{ root.get() };
while (curr) {
if (cmp_less(curr->payload, value)) {
curr = curr->right.get();
}
else if (cmp_less(value, curr->payload)) {
curr = curr->left.get();
}
else {
return true;
}
}
return false;
}
I am aware that there are lots of features to be added. Just wanted to get an idea whether I am going in the right direction so far. | {
"domain": "codereview.stackexchange",
"id": 44988,
"lm_label": null,
"lm_name": null,
"lm_q1_score": null,
"lm_q1q2_score": null,
"lm_q2_score": null,
"openwebmath_perplexity": null,
"openwebmath_score": null,
"tags": "c++, reinventing-the-wheel, tree, binary-search-tree",
"url": null
} |
c++, reinventing-the-wheel, tree, binary-search-tree
Answer:
I am aware that there is lots of features to be added. Just wanted to get an idea if I am going in the right direction so far.
From what I can see it does indeed go in the right direction.
Avoid unnecessarily repeating type names
You have nested templated structs, which require a lot of typing and which make the code less readable. It's therefore helpful to avoid repeating typenames when they are not necessary. The thing to keep in mind is that once the compiler sees which class a function is a member of, you then no longer have to repeat that class's name. By using trailing return types we can make even more use of that. For example:
template<typename T, typename less_than>
template<bool IsConst>
typename BinaryTree<T, less_than>::iterator_base<IsConst>::value_type &BinaryTree<T, less_than>::iterator_base<IsConst>::operator*()
{
return static_cast<BinaryTree<T, less_than>::iterator_base<IsConst>::value_type &>(node->payload);
}
Can be rewritten to:
template<typename T, typename less_than>
template<bool IsConst>
auto BinaryTree<T, less_than>::iterator_base<IsConst>::operator*() -> value_type&
{
return static_cast<value_type &>(node->payload);
}
Note that the static_cast<>() wasn't even necesssary, so you can write:
template<typename T, typename less_than>
template<bool IsConst>
auto BinaryTree<T, less_than>::iterator_base<IsConst>::operator*() -> value_type&
{
return node->payload;
}
You can also use this when declaring a struct that uses inheritance, so instead of:
template<typename T, typename less_than>
struct BinaryTree<T, less_than>::const_iterator : BinaryTree<T, less_than>::iterator_base<true> {};
You can write:
template<typename T, typename less_than>
struct BinaryTree<T, less_than>::const_iterator : iterator_base<true> {}; | {
"domain": "codereview.stackexchange",
"id": 44988,
"lm_label": null,
"lm_name": null,
"lm_q1_score": null,
"lm_q1q2_score": null,
"lm_q2_score": null,
"openwebmath_perplexity": null,
"openwebmath_score": null,
"tags": "c++, reinventing-the-wheel, tree, binary-search-tree",
"url": null
} |
c++, reinventing-the-wheel, tree, binary-search-tree
And you can do this inside function bodies:
template<typename T, typename less_than>
template<bool IsConst>
auto BinaryTree<T, less_than>::iterator_base<IsConst>::operator++() -> iterator_base&
{
…
// node = BinaryTree<T, less_than>::min_element(node->right.get());
node = min_element(node->right.get());
…
}
Make use of the type names you declared
If you declare a type name with using, make sure you use it yourself consistently. Consider iterator_base. First you declare the value_type:
using value_type = std::conditional_t<IsConst, T const, T>;
That's great, but then you forget about it when creating derived types:
using pointer = T*;
using reference = T&;
Those should be:
using pointer = value_type*;
using reference = value_type&;
Luckily, you forgot about the latter two types as well, because:
value_type &operator*();
value_type *operator->();
Those should be:
reference operator*();
pointer operator->();
But of course only if pointer and reference are correctly const-qualified.
Missing things
You already mentioned it needs more features added, but I just wanted to point out some things:
You are not updating size, even though you added that member variable already.
You should have a constructor that takes a less_than parameter by const reference, and use that to initialize cmp_less.
You might want to add a custom allocator function as well.
Use of noexcept and constexpr where appropriate.
Ideally you copy all of std::set()'s interface. | {
"domain": "codereview.stackexchange",
"id": 44988,
"lm_label": null,
"lm_name": null,
"lm_q1_score": null,
"lm_q1q2_score": null,
"lm_q2_score": null,
"openwebmath_perplexity": null,
"openwebmath_score": null,
"tags": "c++, reinventing-the-wheel, tree, binary-search-tree",
"url": null
} |
c++, reinventing-the-wheel, tree, binary-search-tree
Is it going to be useful?
I noticed that the tree isn't balanced. The problem is that it then not going to be very efficient. In fact, in extreme cases it could perform worse than just an unsorted std::vector<T>. Any kind of balancing would make this a much more useful data structure.
Alternatively, it would be nice to let the user build the tree in whatever way they like, inserting new nodes in any place in the tree, and maybe adding functions to do breadth-first search and other tree algorithms and operations. It's no longer just a sorted collection of items then. | {
"domain": "codereview.stackexchange",
"id": 44988,
"lm_label": null,
"lm_name": null,
"lm_q1_score": null,
"lm_q1q2_score": null,
"lm_q2_score": null,
"openwebmath_perplexity": null,
"openwebmath_score": null,
"tags": "c++, reinventing-the-wheel, tree, binary-search-tree",
"url": null
} |
rust, http
Title: URL healthcheck script
Question: Task:
develop a CLI utility for HTTP Health check at a given URL.
The check is performed in a cycle with a specified interval. On each iteration of the HTTP GET activity on the given URL.
There are three options for the test result:
OK(200), in case the request returned HTTP status code 200.
ERR({HTTP_CODE}) if the request returned an HTTP status code other than 200.
URL parsing error, in case the second argument is not a valid HTTP URL. Then the application ends.
The utility takes two arguments:
Integer value of the interval in seconds.
The HTTP URL to be checked.
Example:
~$./program 2 http://example.com/
Checking 'http://example.com/'. Result: OK(200)
Checking 'http://example.com/'. Result: OK(200)
Checking 'http://example.com/'. Result: OK(200)
^C
~$./program 1 http://httpstat.us/500
Checking 'http://httpstat.us/500'. Result: ERR(500)
Checking 'http://httpstat.us/500'. Result: ERR(500)
^C
Could you please review my solution/ and suggest improvements.
My code:
use reqwest; // HTTP request
use clap::Parser; // CLI
use std::{thread, time::Duration};
use url::Url; // Check url format
#[derive(Parser, Debug)]
#[command(author = "mascai", version = "1.0.0", about = "Check interval and URL to check", long_about = None)]
struct Args {
/// Check interval in seconds
check_interval: u64,
/// URL to check
url: String
} | {
"domain": "codereview.stackexchange",
"id": 44989,
"lm_label": null,
"lm_name": null,
"lm_q1_score": null,
"lm_q1q2_score": null,
"lm_q2_score": null,
"openwebmath_perplexity": null,
"openwebmath_score": null,
"tags": "rust, http",
"url": null
} |
rust, http
/// URL to check
url: String
}
fn check_url(client: &reqwest::blocking::Client, url: &str) {
let response = client.get(url).send();
match response {
Ok(data) => {
match data.status() {
reqwest::StatusCode::OK => println!("Checking '{url}'. Result: OK(200)"), // Example: http://yandex.ru
error_code => println!("Checking '{url}'. Result: ERR({})", error_code.as_u16()) // Example: http://httpbin.org/404
}
},
Err(error_data) => { // Example: http://yfakeSite2134123412341.com
let error_code: reqwest::StatusCode = error_data
.status()
.unwrap_or(reqwest::StatusCode::from_u16(500).unwrap());
println!("Checking '{url}'. Result: ERR({})", error_code.as_u16());
}
};
}
fn main() {
let args = Args::parse();
let url = Url::parse(&args.url).expect("URL parsing error"); // Panic in case of invalid
let check_interval: u64 = args.check_interval;
// println!("User innput: {check_interval} {url}");
let client = reqwest::blocking::Client::new();
loop {
check_url(&client, url.as_str());
thread::sleep(Duration::from_secs(check_interval));
}
}
Answer: time span
check_interval: u64,
Wow, that's a lot of time.
A u16 is less than a day.
I was kind of expecting a u32 interval timer,
where four billion is more than a century.
But u64?
That's dozens of times greater than
the current age of the universe.
Maybe it's a little bit of overkill.
PR cleanup
// println!("User innput: {check_interval} {url}");
Debugs are fine during development when you're trying to get things working.
Once you've decided "it is Done" and you're requesting review
for a merge-to-main, then it's time to prune out such commented code.
(Also, nit, typo for "input".)
narrow type
fn check_url(client: &reqwest::blocking::Client, url: &str) { | {
"domain": "codereview.stackexchange",
"id": 44989,
"lm_label": null,
"lm_name": null,
"lm_q1_score": null,
"lm_q1q2_score": null,
"lm_q2_score": null,
"openwebmath_perplexity": null,
"openwebmath_score": null,
"tags": "rust, http",
"url": null
} |
rust, http
narrow type
fn check_url(client: &reqwest::blocking::Client, url: &str) {
Hmmm, .get() seems perfectly willing to accept an Url
instead of a string.
The docs and tutorials tend to express it in terms
of a string for convenience of exposition, but here
you happen to have an Url in hand already.
Using the more restrictive type here would have documentation value.
Plus, it avoids the need to repeatedly re-parse.
other success codes
reqwest::StatusCode::OK => println!("... OK(200)"),
It's not obvious to me that request code shall always be 200 here.
An IMS query could yield 304 Not Modified, or
we could get 204 No Data,
likely others.
Recommend you stick to "OK" and call it a day.
Or report the actual numeric return code.
Consider including a UTC timestamp in each report.
Consider using \r CR to overwrite successive "boring" status reports,
perhaps reporting that there were "{N} successes" in a row.
Consider terminating the loop after K failures.
panic?
Panic'ing doesn't seem like a bad approach, here.
But consider doing a more graceful handling of error and then exiting.
For example, if this code was used by a caller that
requested a fixed number of checks,
or spawned a thread for it,
then the two bits of code would not compose well.
We panic at top-level, but not within a library routine.
As written, you are constraining the adoption
of current and slightly modified versions of
your check_url() routine. | {
"domain": "codereview.stackexchange",
"id": 44989,
"lm_label": null,
"lm_name": null,
"lm_q1_score": null,
"lm_q1q2_score": null,
"lm_q2_score": null,
"openwebmath_perplexity": null,
"openwebmath_score": null,
"tags": "rust, http",
"url": null
} |
algorithm, vb.net, iteration
Title: Increment sequence value for multiple styles
Question: I've found several examples of code to increment various sequence values but they are usually specific to either alpha characters or numeric characters. I wanted something that could increment a sequence to append as a suffix to a file name to "ensure" uniqueness. The "catch" is that sometimes I want numeric values and other times I want alpha characters, while in some cases I might want alphanumeric or even special characters in that file name suffix. I also want to be able to specify a "default length" for the suffix (e.g., I might want the suffix to be 0094 instead of just 94.)
After several revisions, I've written the following which appears to be generating the results I want/expect:
''' <summary>
''' Defines a specific set of characters to find, remove, or replace in an existing string
''' </summary>
Public Enum CharacterType
''' <summary>
''' No character type specified
''' </summary>
NONE
''' <summary>
''' All printable characters
''' </summary>
All
''' <summary>
''' Alpha characters (A-Z or a-z) and/or numeric characters (0-9)
''' </summary>
AlphaNumeric
''' <summary>
''' Alpha characters (A-Z or a-z)
''' </summary>
Alpha
''' <summary>
''' Numeric characters (0-9)
''' </summary>
Numeric
''' <summary>
''' Punctuation or special characters (e.g., ?, #, $, @, !, etc.)
''' </summary>
Punctuation
End Enum | {
"domain": "codereview.stackexchange",
"id": 44990,
"lm_label": null,
"lm_name": null,
"lm_q1_score": null,
"lm_q1q2_score": null,
"lm_q2_score": null,
"openwebmath_perplexity": null,
"openwebmath_score": null,
"tags": "algorithm, vb.net, iteration",
"url": null
} |
algorithm, vb.net, iteration
''' <summary>
''' Increments a sequence value to the next acceptable value for the specified <paramref name="SequenceStyle"/>
''' </summary>
''' <param name="CurrentValue">The current value of the sequence to be incremented.</param>
''' <param name="SequenceStyle">The type(s) of characters that are valid in the sequence return value.</param>
''' <param name="Length">The default length of the sequence. The current value will be padded if its length is less than this value.</param>
''' <returns>
''' A <see cref="String"/> value of the incremented sequence.
''' </returns>
Public Shared Function IncrementSequence(ByVal CurrentValue As String,
Optional ByVal SequenceStyle As CharacterType = CharacterType.NONE,
Optional ByVal Length As Integer = 1,
Optional ByVal ThrowOnInvalidChars As Boolean = False) As String
Dim SkipCharBuffer As String = " !""#$%&'()*+,-./:;<=>?@[\]^_`{|}~"
Dim SkipChars As Char() = SkipCharBuffer.ToCharArray
Select Case SequenceStyle
Case CharacterType.Alpha
If CurrentValue Is Nothing OrElse String.IsNullOrEmpty(CurrentValue.Trim) Then
Return "A".PadLeft(Length, "A"c)
Else
Dim SequenceChars As Char() = CurrentValue.PadLeft(Length, "A"c).ToUpper.ToCharArray
Dim I As Integer = SequenceChars.Length - 1
Dim Alpha As Integer = Asc(SequenceChars(I)) | {
"domain": "codereview.stackexchange",
"id": 44990,
"lm_label": null,
"lm_name": null,
"lm_q1_score": null,
"lm_q1q2_score": null,
"lm_q2_score": null,
"openwebmath_perplexity": null,
"openwebmath_score": null,
"tags": "algorithm, vb.net, iteration",
"url": null
} |
algorithm, vb.net, iteration
Do While I >= 0
If SkipChars.Contains(SequenceChars(I)) Then
If ThrowOnInvalidChars Then
Throw New FormatException("Invalid characters found in the current sequence value.")
Else
I -= 1
End If
ElseIf Alpha >= 65 AndAlso Alpha < 90 Then
SequenceChars(I) = Chr(Asc(SequenceChars(I)) + 1)
Return New String(SequenceChars)
ElseIf Alpha >= 90 Then
SequenceChars(I) = Chr(65)
I -= 1
If I < 0 Then
Dim TempArray(SequenceChars.Length) As Char
For X As Integer = 1 To SequenceChars.Length
TempArray(X) = SequenceChars(X - 1)
Next X
TempArray(0) = Chr(65)
SequenceChars = TempArray
Return New String(SequenceChars)
Else
Alpha = Asc(SequenceChars(I))
End If
Else
If ThrowOnInvalidChars Then
Throw New FormatException("Invalid characters found in the current sequence value.")
End If
End If
Loop | {
"domain": "codereview.stackexchange",
"id": 44990,
"lm_label": null,
"lm_name": null,
"lm_q1_score": null,
"lm_q1q2_score": null,
"lm_q2_score": null,
"openwebmath_perplexity": null,
"openwebmath_score": null,
"tags": "algorithm, vb.net, iteration",
"url": null
} |
algorithm, vb.net, iteration
Return New String(SequenceChars)
End If
Case CharacterType.Numeric
If CurrentValue Is Nothing OrElse String.IsNullOrEmpty(CurrentValue.Trim) Then
Return "1".PadLeft(Length, "0"c)
Else
Dim SequenceChars As Char() = CurrentValue.PadLeft(Length, "0"c).ToUpper.ToCharArray
Dim I As Integer = SequenceChars.Length - 1
Dim Alpha As Integer = Asc(SequenceChars(I))
Do While I >= 0
If SkipChars.Contains(SequenceChars(I)) Then
If ThrowOnInvalidChars Then
Throw New FormatException("Invalid characters found in the current sequence value.")
Else
I -= 1
End If
ElseIf Alpha < 48 Then
SequenceChars(I) = Chr(48)
Return New String(SequenceChars)
ElseIf Alpha >= 48 AndAlso Alpha < 57 Then
SequenceChars(I) = Chr(Asc(SequenceChars(I)) + 1)
Return New String(SequenceChars)
ElseIf Alpha >= 57 Then
SequenceChars(I) = Chr(48)
I -= 1
If I < 0 Then
Dim TempArray(SequenceChars.Length) As Char
For X As Integer = 1 To SequenceChars.Length
TempArray(X) = SequenceChars(X - 1)
Next X | {
"domain": "codereview.stackexchange",
"id": 44990,
"lm_label": null,
"lm_name": null,
"lm_q1_score": null,
"lm_q1q2_score": null,
"lm_q2_score": null,
"openwebmath_perplexity": null,
"openwebmath_score": null,
"tags": "algorithm, vb.net, iteration",
"url": null
} |
algorithm, vb.net, iteration
TempArray(0) = Chr(49)
SequenceChars = TempArray
Return New String(SequenceChars)
Else
Alpha = Asc(SequenceChars(I))
End If
Else
If ThrowOnInvalidChars Then
Throw New FormatException("Invalid characters found in the current sequence value.")
End If
End If
Loop
Return New String(SequenceChars)
End If
Case CharacterType.AlphaNumeric
If CurrentValue Is Nothing OrElse String.IsNullOrEmpty(CurrentValue.Trim) Then
Return "1".PadLeft(Length, "0"c)
Else
Dim SequenceChars As Char() = CurrentValue.ToUpper.PadLeft(Length, "0"c).ToCharArray
Dim I As Integer = SequenceChars.Length - 1
Dim Alpha As Integer = Asc(SequenceChars(I)) | {
"domain": "codereview.stackexchange",
"id": 44990,
"lm_label": null,
"lm_name": null,
"lm_q1_score": null,
"lm_q1q2_score": null,
"lm_q2_score": null,
"openwebmath_perplexity": null,
"openwebmath_score": null,
"tags": "algorithm, vb.net, iteration",
"url": null
} |
algorithm, vb.net, iteration
Do While I >= 0
If SkipChars.Contains(SequenceChars(I)) Then
If ThrowOnInvalidChars Then
Throw New FormatException("Invalid characters found in the current sequence value.")
Else
I -= 1
End If
ElseIf Alpha < 48 Then
SequenceChars(I) = Chr(48)
Return New String(SequenceChars)
ElseIf Alpha >= 48 AndAlso Alpha < 57 Then
SequenceChars(I) = Chr(Asc(SequenceChars(I)) + 1)
Return New String(SequenceChars)
ElseIf Alpha >= 57 AndAlso Alpha < 65 Then
SequenceChars(I) = Chr(65)
Return New String(SequenceChars)
ElseIf Alpha >= 65 AndAlso Alpha < 90 Then
SequenceChars(I) = Chr(Asc(SequenceChars(I)) + 1)
Return New String(SequenceChars)
ElseIf Alpha >= 90 Then
SequenceChars(I) = Chr(48)
I -= 1
If I < 0 Then
Dim TempArray(SequenceChars.Length) As Char
For X As Integer = 1 To SequenceChars.Length
TempArray(X) = SequenceChars(X - 1)
Next X | {
"domain": "codereview.stackexchange",
"id": 44990,
"lm_label": null,
"lm_name": null,
"lm_q1_score": null,
"lm_q1q2_score": null,
"lm_q2_score": null,
"openwebmath_perplexity": null,
"openwebmath_score": null,
"tags": "algorithm, vb.net, iteration",
"url": null
} |
algorithm, vb.net, iteration
TempArray(0) = Chr(49)
SequenceChars = TempArray
Return New String(SequenceChars)
Else
Alpha = Asc(SequenceChars(I))
End If
Else
If ThrowOnInvalidChars Then
Throw New FormatException("Invalid characters found in the current sequence value.")
End If
End If
Loop
Return New String(SequenceChars)
End If
Case CharacterType.All
If CurrentValue Is Nothing OrElse String.IsNullOrEmpty(CurrentValue.Trim) Then
Return "1".PadLeft(Length, "0"c)
Else
Dim SequenceChars As Char() = CurrentValue.ToUpper.PadLeft(Length, "0"c).ToCharArray
Dim I As Integer
Dim Alpha As Integer
For C As Integer = 0 To SequenceChars.Length - 1
If Path.GetInvalidFileNameChars.Contains(SequenceChars(C)) OrElse Path.GetInvalidPathChars.Contains(SequenceChars(C)) Then
SequenceChars(C) = "_"c
ElseIf Asc(SequenceChars(C)) >= 0 AndAlso Asc(SequenceChars(C)) <= 31 Then
SequenceChars(C) = "_"c
ElseIf Asc(SequenceChars(C)) = 124 Then
SequenceChars(C) = "_"c
ElseIf Asc(SequenceChars(C)) = 127 Then
SequenceChars(C) = "_"c
End If
Next C
I = SequenceChars.Length - 1
Do While I >= 0
Alpha = Asc(SequenceChars(I)) | {
"domain": "codereview.stackexchange",
"id": 44990,
"lm_label": null,
"lm_name": null,
"lm_q1_score": null,
"lm_q1q2_score": null,
"lm_q2_score": null,
"openwebmath_perplexity": null,
"openwebmath_score": null,
"tags": "algorithm, vb.net, iteration",
"url": null
} |
algorithm, vb.net, iteration
Do While I >= 0
Alpha = Asc(SequenceChars(I))
If SkipChars.Contains(SequenceChars(I)) Then
I -= 1
ElseIf Alpha < 48 Then
SequenceChars(I) = Chr(48)
Return New String(SequenceChars)
ElseIf Alpha >= 48 AndAlso Alpha < 57 Then
SequenceChars(I) = Chr(Asc(SequenceChars(I)) + 1)
Return New String(SequenceChars)
ElseIf Alpha >= 57 AndAlso Alpha < 65 Then
SequenceChars(I) = Chr(65)
Return New String(SequenceChars)
ElseIf Alpha >= 65 AndAlso Alpha < 90 Then
SequenceChars(I) = Chr(Asc(SequenceChars(I)) + 1)
Return New String(SequenceChars)
ElseIf Alpha >= 90 Then
SequenceChars(I) = Chr(48)
I -= 1
If I < 0 Then
Dim TempArray(SequenceChars.Length) As Char
For X As Integer = 1 To SequenceChars.Length
TempArray(X) = SequenceChars(X - 1)
Next X
TempArray(0) = Chr(49)
SequenceChars = TempArray
Return New String(SequenceChars)
End If
End If
Loop | {
"domain": "codereview.stackexchange",
"id": 44990,
"lm_label": null,
"lm_name": null,
"lm_q1_score": null,
"lm_q1q2_score": null,
"lm_q2_score": null,
"openwebmath_perplexity": null,
"openwebmath_score": null,
"tags": "algorithm, vb.net, iteration",
"url": null
} |
algorithm, vb.net, iteration
Return New String(SequenceChars)
End If
Case CharacterType.NONE
Return IncrementSequence(CurrentValue, GetSequenceStyle(CurrentValue))
Case Else
If ThrowOnInvalidChars Then
Throw New ArgumentOutOfRangeException(NameOf(SequenceStyle), SequenceStyle, $"The specified {NameOf(CharacterType)} does not exist.")
Else
Return Nothing
End If
End Select
End Function
''' <summary>
''' Gets the type(s) of characters that exist in the current sequence value.
''' </summary>
''' <param name="CurrentSequenceValue">The sequence to check for character type(s).</param>
''' <returns>
''' The <see cref="CharacterType"/> value identifying the valid type(s) of characters
''' for the specified <paramref name="CurrentSequenceValue"/>
''' </returns>
Private Shared Function GetSequenceStyle(ByVal CurrentSequenceValue As String) As CharacterType
Dim Alpha As Boolean = False
Dim Numeric As Boolean = False
Dim Punctuation As Boolean = False
For Each C As Char In CurrentSequenceValue.ToUpper.ToCharArray
If Char.IsNumber(C) Then
Numeric = True
ElseIf Char.IsLetter(C) Then
Alpha = True
ElseIf Char.IsPunctuation(C) Then
Punctuation = True
End If
Next C
If Numeric AndAlso Alpha AndAlso Punctuation Then
Return CharacterType.All
ElseIf Numeric AndAlso Alpha AndAlso Not Punctuation Then
Return CharacterType.AlphaNumeric
ElseIf Alpha AndAlso Not Punctuation Then
Return CharacterType.Alpha
Else
Return CharacterType.Numeric
End If
End Function
I've tested with up to 100,000 simple iterations of the method:
Dim Suffix As String = String.Empty
For I As Integer = 0 To 100000
Suffix = IncrementSequence(Suffix, CharacterType.Numeric)
Console.WriteLine("New suffix: " & Suffix)
Next I | {
"domain": "codereview.stackexchange",
"id": 44990,
"lm_label": null,
"lm_name": null,
"lm_q1_score": null,
"lm_q1q2_score": null,
"lm_q2_score": null,
"openwebmath_perplexity": null,
"openwebmath_score": null,
"tags": "algorithm, vb.net, iteration",
"url": null
} |
algorithm, vb.net, iteration
This produces results ending with 100001, as expected.
Changing to CharacterType.Alpha gives me an ending value of EQXE, while changing to CharacterType.AlphaNumeric gives me an ending value of 255T. (NGL, I'm not doing the math on that to confirm it's "right").
I've also (so far) successfully used this in my IncrementExistingFileName() method:
Public Shared Function IncrementExistingFileName(ByVal OriginalFileName As String, Optional ByVal SuffixStyle As CharacterType = CharacterType.Numeric, Optional ByVal SuffixLength As Integer = 2) As String
Dim NewFileName As String = OriginalFileName
Dim FilePath As String = Path.GetDirectoryName(OriginalFileName)
Dim FileName As String = Path.GetFileNameWithoutExtension(OriginalFileName)
Dim FileExt As String = Path.GetExtension(OriginalFileName)
Dim Suffix As String = String.Empty
While File.Exists(NewFileName)
Suffix = IncrementSequence(Suffix, SuffixStyle, SuffixLength)
NewFileName = $"{FilePath}\{FileName}_{Suffix}{FileExt}"
End While
Return NewFileName
End Function
As stated at the beginning of this question, I've looked at numerous examples of code, including the suggestion(s) from Incrementing a sequence of letters by one on this site, as well as a CodeProject article from 2006 that just didn't quite work right.
At this point, I guess I'm looking for some general feedback on the IncrementSequence() method. Am I "doing it right"? I mean, as I said, my testing so far indicates that it's working, but I'm aware that I still may have managed to overlook something "obvious" to someone else. Is there anything that I've done that could be done more effectively?
NOTE: I am aware that I deviate a bit from the .NET Naming Guidelines with regards to using PascalCase in instances where camelCase is preferred, but this is in line with my company's coding standards.
Answer: declarations
DIM I As Integer = SequenceChars.Length - 1 | {
"domain": "codereview.stackexchange",
"id": 44990,
"lm_label": null,
"lm_name": null,
"lm_q1_score": null,
"lm_q1q2_score": null,
"lm_q2_score": null,
"openwebmath_perplexity": null,
"openwebmath_score": null,
"tags": "algorithm, vb.net, iteration",
"url": null
} |
algorithm, vb.net, iteration
Answer: declarations
DIM I As Integer = SequenceChars.Length - 1
Wow, that's super funny, guess we have to pick some way to make declarations.
I remember
Alcock
teaching me DIM D(52) to allocate space for a deck of playing cards.
Guess they didn't want to invent a new keyword when limiting a variable to int32.
On the plus side we don't have to refer to $SequenceChars,
so that's an improvement.
Ok, sorry, moving on.
counting
The high level concept you should be pursuing here is that we have
a serial, which we increment, and which we output in some convenient base.
Now, we could start incrementing from zero and output a base-2 binary result,
or a base-10 decimal result. But here we wish to output a base-27 result.
So 0 is INVISIBLE SPACE (elided), and 1 .. 26 are "A" .. "Z".
(I will represent INVISIBLE as _ underscore, to make it visible.
Some folks might prefer ZWSP.)
It lets us distinguish between A, AA, AAA and so on,
in a way that zero would not.
One way to think of the decimal integer 2023 is: 0... ...000002023.
That is, think of it as having an infinite prefix of zeros before it,
which by convention we do not display.
Similarly unity in base-27 is ...00000A or ..._____A, with INVISIBLE zeros elided
for display purposes.
Converting unsigned integer to its base-27 display form is straightforward.
When caller asks us to increment the integer,
we should check to see if the display form contains any INVISIBLE
characters that would not be displayed.
If so we continue to increment,
until obtaining an integer for which all digits (A..Z) shall be visibly displayed.
Consider 26 which displays as Z.
Incrementing to 27 takes us from _Z to A_, which contains an INVISIBLE character that wants to be displayed but cannot.
So we again increment to 28, or AA, a valid return value. | {
"domain": "codereview.stackexchange",
"id": 44990,
"lm_label": null,
"lm_name": null,
"lm_q1_score": null,
"lm_q1q2_score": null,
"lm_q2_score": null,
"openwebmath_perplexity": null,
"openwebmath_score": null,
"tags": "algorithm, vb.net, iteration",
"url": null
} |
algorithm, vb.net, iteration
We don't have to use base-27, as base-26 could be made to work,
with A being zero instead of one as above.
We would need a string or a (length, value) tuple.
Increment the length when counting past Z, ZZ, ZZZ etc.
magic numbers
ElseIf Alpha >= 65 AndAlso Alpha < 90 Then
...
ElseIf Alpha >= 90 Then
I don't understand those comparisons at all.
It looks buggy.
Rephrasing slightly the 65 comparison is Alpha >= ORD("A"),
with a conjunct of Alpha < ORD("Z").
But we wanted <= there. Introducing
magic numbers
has obscured Author's Intent to the point where not even he
can discern if there's a bug or not. | {
"domain": "codereview.stackexchange",
"id": 44990,
"lm_label": null,
"lm_name": null,
"lm_q1_score": null,
"lm_q1q2_score": null,
"lm_q2_score": null,
"openwebmath_perplexity": null,
"openwebmath_score": null,
"tags": "algorithm, vb.net, iteration",
"url": null
} |
python
Title: Mastermind game in Python
Question: I am a C#/.Net developer and have decided it is time to branch out and really learn Python. I started with a simple implementation of a Mastermind-esque game. Any comments about the code would be greatly appreciated. I already know the gameplay isn't perfect, but it was just a quick attempt. I also am aware that there isn't much user input checking, but again, quick attempt.
import random
class Game(object):
def run(self):
guesses = []
game_states = []
length = int(input("Choose length of code to break: "))
code = [random.randint(0, 9) for i in range(length)]
def take_guess():
correct_guess_length = False
while not correct_guess_length:
guess = input("Guess a number of length {0}: ".format(length))
if len(guess) != length:
print("Guesses must be a number of length {0}.".format(length))
else:
correct_guess_length = True
return guess
def check_guess(guess):
return all([x == y for x, y in zip(guess, code)])
def evaluate_guess(guess):
new_state = []
for pos, number in enumerate(guess):
if code[pos] == number:
new_state.append(str(number))
elif number in code:
new_state.append("O")
else:
new_state.append("X")
game_states.append(''.join([c for c in new_state]))
def print_game_state():
print()
for guess, state in zip(guesses, game_states):
print("{0}\t{1}".format(guess, state)) | {
"domain": "codereview.stackexchange",
"id": 44991,
"lm_label": null,
"lm_name": null,
"lm_q1_score": null,
"lm_q1q2_score": null,
"lm_q2_score": null,
"openwebmath_perplexity": null,
"openwebmath_score": null,
"tags": "python",
"url": null
} |
python
correct = False
while not correct:
guess = take_guess()
guesses.append(guess)
guess_as_ints = [int(c) for c in guess]
if not check_guess(guess_as_ints):
evaluate_guess(guess_as_ints)
print_game_state()
else:
print("You guessed the code was {0}! Congratulations!".format(''.join([str(i) for i in code])))
correct = True
if __name__ == '__main__':
game = Game()
game.run()
Answer: Organization
As Simon points out, you shouldn't put the list of functions inside of run. It doesn't make much sense. Move them out into the class.
Use self
self in python is equivalent to this in C# and many other languages.
This:
guesses = []
game_states = []
length = int(input("Choose length of code to break: "))
code = [random.randint(0, 9) for i in range(length)]
Should be this:
def __init__(self):
self.guesses = []
self.game_states = []
self.code = [] # Add this later when you define length.
(Also, I would keep length as a local variable defined in run and then refer to len(self.code) instead.)
I would advise you look at how Python classes work.
You can replace random.randint(0, 9) with random.randrange(10).
Furthermore, once you pull the functions out of run, things like:
def take_guess():
become:
def take_guess(self):
Naming
correct_guess_length = False
I expect a varaible with the name of length have some sort of integer (maybe real?) value. A boolean? Not often.
You don't really need this anyway!
else:
correct_guess_length = True
Can just be:
else:
break
I would probably just get rid of that too and say:
else:
return guess
Same thing goes for:
correct = False
while not correct:
... | {
"domain": "codereview.stackexchange",
"id": 44991,
"lm_label": null,
"lm_name": null,
"lm_q1_score": null,
"lm_q1q2_score": null,
"lm_q2_score": null,
"openwebmath_perplexity": null,
"openwebmath_score": null,
"tags": "python",
"url": null
} |
python
Same thing goes for:
correct = False
while not correct:
...
You can get rid of these and use a break statement instead.
randrange
code = [random.randint(0, 9) for i in range(length)]
Is pretty good except, randrange is a little more specialized for this:
code = [random.randrange(10) for _ in range(length)]
(Also, when you disregard a variable the convention is to use _, not i.)
__str__
Since you rap everything in a game object, maybe you should give it a string representation overloading the __str__ function, and just print out the string representation of itself. Move print_game_state to __str__. | {
"domain": "codereview.stackexchange",
"id": 44991,
"lm_label": null,
"lm_name": null,
"lm_q1_score": null,
"lm_q1q2_score": null,
"lm_q2_score": null,
"openwebmath_perplexity": null,
"openwebmath_score": null,
"tags": "python",
"url": null
} |
python, performance, docker, dockerfile
Title: Install specific version of Python in docker
Question: Downloading specific version like 3.11.1 from https://www.python.org/ftp/python/3.11.1/Python-3.11.1.tgz and installing ./configure --enable-optimizations && make install is slow (30 - 40 mins), on GitHub actions.
Dockerfile:
FROM --platform=linux/amd64 ubuntu:22.04 as base
USER root
ENV PYTHONDONTWRITEBYTECODE 1
ENV PYTHONUNBUFFERED 1
ENV DEBIAN_FRONTEND noninteractive
COPY . /app
WORKDIR /app
COPY ZscalerCertificate.crt /usr/local/share/ca-certificates/ZscalerCertificate.crt
RUN find /tmp -name \*.deb -exec rm {} +
RUN apt-get update && \
apt-get upgrade -y && \
apt-get install -y software-properties-common ca-certificates &&\
update-ca-certificates
RUN apt-get update &&\
apt-get upgrade -y && \
apt-get install -y --no-install-recommends curl gcc g++ gnupg unixodbc-dev openssl git &&\
rm -rf /var/lib/apt/lists/*
RUN apt-get update && apt-get upgrade
RUN apt-get install -y build-essential zlib1g-dev libncurses5-dev libgdbm-dev libssl-dev \
libreadline-dev libffi-dev wget libbz2-dev libsqlite3-dev
RUN mkdir /python && cd /python
RUN wget https://www.python.org/ftp/python/3.11.1/Python-3.11.1.tgz
RUN tar -zxvf Python-3.11.1.tgz
RUN cd Python-3.11.1 && ls -lhR && ./configure --enable-optimizations && make install
What is the optimal way to install python specific version? and how to reduce the build time?
Answer: This is a bad layer:
RUN apt-get update && apt-get upgrade
That locks in the package lists permanently in a layer. Worse, it means changes to the next layer may use a cached version of this layer instead of getting an update. That could mean the apt-get install tries to get packages no longer in the archive.
Combine it with the install command and post-install size reduction, as you did for the earlier package installs.
Each of those ought to apt-get clean, too, to remove the contents of /var/cache/apt/archives, which tend to be large. | {
"domain": "codereview.stackexchange",
"id": 44992,
"lm_label": null,
"lm_name": null,
"lm_q1_score": null,
"lm_q1q2_score": null,
"lm_q2_score": null,
"openwebmath_perplexity": null,
"openwebmath_score": null,
"tags": "python, performance, docker, dockerfile",
"url": null
} |
python, performance, docker, dockerfile
Similarly, this one leaves the large archive lying around:
wget https://www.python.org/ftp/python/3.11.1/Python-3.11.1.tgz
We should be immediately unpacking then removing it (all in a single layer, to keep the container image reasonably small). Preferably, we should unpack, build and clean, keeping just the installed result. | {
"domain": "codereview.stackexchange",
"id": 44992,
"lm_label": null,
"lm_name": null,
"lm_q1_score": null,
"lm_q1q2_score": null,
"lm_q2_score": null,
"openwebmath_perplexity": null,
"openwebmath_score": null,
"tags": "python, performance, docker, dockerfile",
"url": null
} |
java, compression, canvas, javafx, video
Title: Comparing video recording algorithms in Java: no-compression vs. naive diff compressor
Question: Usage of the program is in Facebook.
Intro
In this JavaFX program, a user is presented with a white canvas with a black circle at the center of the canvas. Then, the user has 10 seconds to record a video by dragging the circle via mouse. During the recording, there are two different video recording algorithms recording each frame. The algorithms are as follows:
No-compression: each frame is recorded on a pixel-by-pixel basis; one bit per pixel (white vs. black),
Naive compressor: the first frame is stored just like in 1, yet after that it records only the "diff" between two consecutive frames.
More precisely, in algorithm 2, each new frame is computed as follows: Compare the previous and the next frames; store the number of pixels \$N\$ that has changed between the two. Next, for each changed pixel \$(x, y)\$, store it after written value of \$N\$.
Critique request
Please, tell me anything that comes to mind.
Source code
com.github.coderodde.compression.util.BitArrayBuilder.java:
package com.github.coderodde.compression.util;
import java.util.Arrays;
/**
* This class implements a bit array builder for storing the video frames.
*
* @author Rodion "rodde" Efremov
* @version 1.6 (Jul 18, 2023)
* @since 1.6 (Jul 18, 2023)
*/
public final class BitArrayBuilder { | {
"domain": "codereview.stackexchange",
"id": 44993,
"lm_label": null,
"lm_name": null,
"lm_q1_score": null,
"lm_q1q2_score": null,
"lm_q2_score": null,
"openwebmath_perplexity": null,
"openwebmath_score": null,
"tags": "java, compression, canvas, javafx, video",
"url": null
} |
java, compression, canvas, javafx, video
private static final int DEFAULT_LONG_ARRAY_CAPACITY = 50_000;
/**
* This array stores the actual bits.
*/
private long[] bitArray;
/**
* This field specifies how many bits there are in this builder.
*/
private int size;
/**
* Constructs a bit array builder with default capacity.
*/
public BitArrayBuilder() {
this(DEFAULT_LONG_ARRAY_CAPACITY * Long.SIZE);
}
/**
* Constructs a bit array builder capable of holding
* {@code initialNumberOfBits} bits.
*
* @param initialNumberOfBits the initial requested capacity.
*/
public BitArrayBuilder(int initialNumberOfBits) {
this.bitArray = new long[getInitialNumberOfLongs(initialNumberOfBits)];
}
/**
* Returns the number of bits stored in this builder.
*
* @return the number of bits.
*/
public int size() {
return size;
}
/**
* Appends {@code length} least-significant bits from {@code bitsToAppend}
* to this bit array builder.
*
* @param bitsToAppend the {@code long} value holding the bits.
* @param length the number of least-significant bits to append.
*/
public void appendBits(long bitsToAppend, int length) {
expandTableIfNeeded(size + length);
for (int bitIndex = 0; bitIndex < length; bitIndex++) {
appendBit(((bitsToAppend >> bitIndex) & 0x1L) != 0);
}
}
/**
* Reads {@code length} bits starting from index {@code index}.
*
* @param index the leftmost index of the bit range to read.
* @param length the length of the bit range to read.
* @return the {@code length} bits.
*/
public long readBits(int index, int length) {
long ret = 0L;
for (int i = index, bitIndex = 0; i < index + length; i++, bitIndex++) {
boolean bit = readBit(i);
if (bit) { | {
"domain": "codereview.stackexchange",
"id": 44993,
"lm_label": null,
"lm_name": null,
"lm_q1_score": null,
"lm_q1q2_score": null,
"lm_q2_score": null,
"openwebmath_perplexity": null,
"openwebmath_score": null,
"tags": "java, compression, canvas, javafx, video",
"url": null
} |
java, compression, canvas, javafx, video
boolean bit = readBit(i);
if (bit) {
ret |= (1 << bitIndex);
}
}
return ret;
}
/**
* Reads the {@code index}th bit.
*
* @param index the index of the bit to read.
* @return a bit, {@code true} for the 1 and {@code false} for the 0.
*/
private boolean readBit(int index) {
int longIndex = index / Long.SIZE;
long dataLong = bitArray[longIndex];
index %= Long.SIZE;
long mask = 1L << index;
return (dataLong & mask) != 0;
}
/**
* Returns the shortest byte array capable of holding all the bits in this
* bit array builder.
*
* @return the byte content of this builder.
*/
public byte[] getBytes() {
int numberOfBytes = size / Byte.SIZE;
int remainder = size % Byte.SIZE;
int byteArrayLength = numberOfBytes + (remainder != 0 ? 1 : 0);
byte[] bytes = new byte[byteArrayLength];
for (int byteIndex = 0; byteIndex < bytes.length; byteIndex++) {
bytes[byteIndex] = getDataByte(byteIndex);
}
return bytes;
}
/**
* Returns the {@code byteIndex}th byte.
*
* @param byteIndex the byte index.
* @return the byte value at index {@code byteIndex}.
*/
private byte getDataByte(int byteIndex) {
long longData = bitArray[byteIndex / Long.BYTES];
byteIndex %= Long.BYTES;
switch (byteIndex) {
case 0:
return (byte)(longData);
case 1:
return (byte)((longData >> 8) & 0xFF);
case 2:
return (byte)((longData >> 16) & 0xFF);
case 3:
return (byte)((longData >> 24) & 0xFF);
case 4:
return (byte)((longData >> 32) & 0xFF); | {
"domain": "codereview.stackexchange",
"id": 44993,
"lm_label": null,
"lm_name": null,
"lm_q1_score": null,
"lm_q1q2_score": null,
"lm_q2_score": null,
"openwebmath_perplexity": null,
"openwebmath_score": null,
"tags": "java, compression, canvas, javafx, video",
"url": null
} |
java, compression, canvas, javafx, video
case 4:
return (byte)((longData >> 32) & 0xFF);
case 5:
return (byte)((longData >> 40) & 0xFF);
case 6:
return (byte)((longData >> 48) & 0xFF);
case 7:
return (byte)((longData >> 56) & 0xFF);
default:
throw new IllegalStateException("Should not get here ever.");
}
}
/**
* Implements the actual appending of a bit to the tail of this bit array
* builder.
*
* @param bit the bit to append. If is {@code true}, a 1-bit is appended,
* and 0-bit otherwise.
*/
private void appendBit(boolean bit) {
int longIndex = size / Long.SIZE;
int longBitsIndex = size - longIndex * Long.SIZE;
long mask = 0x1L << longBitsIndex;
if (bit) {
bitArray[longIndex] |= mask;
} else {
bitArray[longIndex] &= ~mask;
}
size++;
}
/**
* Computes the initial number of {@code long} values sufficient to hold
* {@code initialNumberOfBits} bits.
*
* @param initialNumberOfBits the number of bits to accommodate.
* @return the number of longs needed to store all the bits.
*/
private int getInitialNumberOfLongs(int initialNumberOfBits) {
int longs = initialNumberOfBits / Long.SIZE;
int remainder = initialNumberOfBits % Long.SIZE;
return longs + (remainder != 0 ? 1 : 0);
}
/**
* Doubles the capacity of the actual bit array.
*
* @param requestedCapacity the requested capacity.
*/
private void expandTableIfNeeded(int requestedCapacity) {
if (requestedCapacity > bitArray.length * Long.SIZE) {
long[] newBitArray =
Arrays.copyOf(
bitArray, | {
"domain": "codereview.stackexchange",
"id": 44993,
"lm_label": null,
"lm_name": null,
"lm_q1_score": null,
"lm_q1q2_score": null,
"lm_q2_score": null,
"openwebmath_perplexity": null,
"openwebmath_score": null,
"tags": "java, compression, canvas, javafx, video",
"url": null
} |
java, compression, canvas, javafx, video
Arrays.copyOf(
bitArray,
Math.max(bitArray.length * 2, requestedCapacity));
int sizeToCopy = size / Long.SIZE + (size % Long.SIZE == 0 ? 0 : 1);
System.arraycopy(bitArray, 0, newBitArray, 0, sizeToCopy);
bitArray = newBitArray;
}
}
} | {
"domain": "codereview.stackexchange",
"id": 44993,
"lm_label": null,
"lm_name": null,
"lm_q1_score": null,
"lm_q1q2_score": null,
"lm_q2_score": null,
"openwebmath_perplexity": null,
"openwebmath_score": null,
"tags": "java, compression, canvas, javafx, video",
"url": null
} |
java, compression, canvas, javafx, video
com.github.coderodde.compression.util.CircleVideoShape.java:
package com.github.coderodde.compression.util;
import java.util.concurrent.atomic.AtomicInteger; | {
"domain": "codereview.stackexchange",
"id": 44993,
"lm_label": null,
"lm_name": null,
"lm_q1_score": null,
"lm_q1q2_score": null,
"lm_q2_score": null,
"openwebmath_perplexity": null,
"openwebmath_score": null,
"tags": "java, compression, canvas, javafx, video",
"url": null
} |
java, compression, canvas, javafx, video
/**
* This class implements the circle video shape for recording.
*
* @author Rodion "rodde" Efremov
* @version 1.6 (Jul 18, 2023)
* @since 1.6 (Jul 18, 2023)
*/
public final class CircleVideoShape {
/**
* The width of the canvas that contains this circle.
*/
private final int pixelMatrixWidth;
/**
* The height of the canvas that contains this circle.
*/
private final int pixelMatrixHeight;
/**
* The radius of this circle.
*/
private final int radius;
/**
* The center X-coordinate.
*/
private final AtomicInteger centerX;
/**
* The center Y-coordinate.
*/
private final AtomicInteger centerY;
/**
* Constructs a new circle.
*
* @param pixelMatrixWidth the width of the containing canvas.
* @param pixelMatrixHeight the height of the containing canvas.
* @param radius the radius of the circle.
*/
public CircleVideoShape(
int pixelMatrixWidth,
int pixelMatrixHeight,
int radius) {
this.pixelMatrixWidth = pixelMatrixWidth;
this.pixelMatrixHeight = pixelMatrixHeight;
this.radius = radius;
this.centerX = new AtomicInteger(pixelMatrixWidth / 2);
this.centerY = new AtomicInteger(pixelMatrixHeight / 2);
}
public int getRadius() {
return radius;
}
public int getCenterX() {
return centerX.get();
}
public int getCenterY() {
return centerY.get();
}
public void setCenterX(int centerX) {
this.centerX.set(centerX);
}
public void setCenterY(int centerY) {
this.centerY.set(centerY);
}
/**
* Returns the entire pixel color matrix.
*
* @return pixel color matrix.
*/
public PixelColor[][] getColorMatrix() {
PixelColor[][] pixelColorMatrix = new PixelColor[pixelMatrixHeight] | {
"domain": "codereview.stackexchange",
"id": 44993,
"lm_label": null,
"lm_name": null,
"lm_q1_score": null,
"lm_q1q2_score": null,
"lm_q2_score": null,
"openwebmath_perplexity": null,
"openwebmath_score": null,
"tags": "java, compression, canvas, javafx, video",
"url": null
} |
java, compression, canvas, javafx, video
PixelColor[][] pixelColorMatrix = new PixelColor[pixelMatrixHeight]
[pixelMatrixWidth];
for (int y = 0; y < pixelMatrixHeight; y++) {
for (int x = 0; x < pixelMatrixWidth; x++) {
pixelColorMatrix[y][x] = getPixelColorAt(x, y);
}
}
return pixelColorMatrix;
}
/**
* Computes the pixel color of the pixel at coordinates {@code (x, y)]}.
*
* @param x the X-coordinate of the pixel.
* @param y the Y-coordinate of the pixel.
* @return the actual color of the pixel.
*/
private PixelColor getPixelColorAt(int x, int y) {
int dx = x - centerX.get();
int dy = y - centerY.get();
int dist2 = dx * dx + dy * dy;
double dist = Math.sqrt(dist2);
return dist > radius ? PixelColor.WHITE : PixelColor.BLACK;
}
} | {
"domain": "codereview.stackexchange",
"id": 44993,
"lm_label": null,
"lm_name": null,
"lm_q1_score": null,
"lm_q1q2_score": null,
"lm_q2_score": null,
"openwebmath_perplexity": null,
"openwebmath_score": null,
"tags": "java, compression, canvas, javafx, video",
"url": null
} |
java, compression, canvas, javafx, video
com.github.coderodde.compression.util.PixelColor.java:
package com.github.coderodde.compression.util;
public enum PixelColor {
WHITE,
BLACK;
}
com.github.coderodde.compression.util.Utils.java:
package com.github.coderodde.compression.util; | {
"domain": "codereview.stackexchange",
"id": 44993,
"lm_label": null,
"lm_name": null,
"lm_q1_score": null,
"lm_q1q2_score": null,
"lm_q2_score": null,
"openwebmath_perplexity": null,
"openwebmath_score": null,
"tags": "java, compression, canvas, javafx, video",
"url": null
} |
java, compression, canvas, javafx, video
/**
* This class contains various utility methods.
*
* @author Rodion "rodde" Efremov
* @version 1.6 (Jul 18, 2023)
* @since 1.6 (Jul 18, 2023)
*/
public final class Utils {
public static void sleep(long milliseconds) {
try {
Thread.sleep(milliseconds);
} catch (InterruptedException ex) {
}
}
public static void sleep(long milliseconds, int nanoseconds) {
try {
Thread.sleep(milliseconds, nanoseconds);
} catch (InterruptedException ex) {
}
}
public static void sleep(SleepDuration sleepDuration) {
try {
Thread.sleep(sleepDuration.millisecondsPart,
sleepDuration.nanosecondsPart);
} catch (InterruptedException ex) {
}
}
/**
* Returns the minimum number of bits sufficient to store the value
* {@code maximumValue}.
*
* @param maximumValue the integer value we wish to store.
* @return number of bits sufficient to store the input value.
*/
public static int computeNumberOfBitsToStore(int maximumValue) {
if (maximumValue == 0) {
return 1;
}
int bits = 0;
while (maximumValue != 0) {
maximumValue /= 2;
bits++;
}
return bits;
}
/**
* Returns the number of nanoseconds which it takes to call the
* {@link Trhead.sleep}.
*
* @return the number of nanoseconds.
*/
public static long getThreadSleepCallDuration() {
long start = System.nanoTime();
sleep(0L);
long duration = System.nanoTime() - start;
return Math.max(duration, 0L);
}
public static SleepDuration getFrameSleepDuration(int framesPerSecond) {
long sleepCallDuration = getThreadSleepCallDuration(); | {
"domain": "codereview.stackexchange",
"id": 44993,
"lm_label": null,
"lm_name": null,
"lm_q1_score": null,
"lm_q1q2_score": null,
"lm_q2_score": null,
"openwebmath_perplexity": null,
"openwebmath_score": null,
"tags": "java, compression, canvas, javafx, video",
"url": null
} |
java, compression, canvas, javafx, video
long sleepCallDuration = getThreadSleepCallDuration();
long durationNanoseconds = 1_000_000_000 / framesPerSecond
- sleepCallDuration;
long durationMilliseconds = durationNanoseconds / 1_000_000;
long durationNanosecondsPart =
durationNanoseconds - durationMilliseconds * 1_000_000;
return new SleepDuration(durationMilliseconds,
(int) durationNanosecondsPart);
}
public static final class SleepDuration {
public final long millisecondsPart;
public final int nanosecondsPart;
SleepDuration(long milliseconds, int nanoseconds) {
this.millisecondsPart = milliseconds;
this.nanosecondsPart = nanoseconds;
}
}
} | {
"domain": "codereview.stackexchange",
"id": 44993,
"lm_label": null,
"lm_name": null,
"lm_q1_score": null,
"lm_q1q2_score": null,
"lm_q2_score": null,
"openwebmath_perplexity": null,
"openwebmath_score": null,
"tags": "java, compression, canvas, javafx, video",
"url": null
} |
java, compression, canvas, javafx, video
com.github.coderodde.compression.util.VideoScreenCanvas.java:
package com.github.coderodde.compression.util;
import javafx.scene.canvas.Canvas;
import javafx.scene.canvas.GraphicsContext;
import javafx.scene.image.Image;
import javafx.scene.image.PixelWriter;
import javafx.scene.image.WritableImage;
import javafx.scene.paint.Color;
/**
* This class implements the video screen canvas.
*
* @author Rodion "rodde" Efremov
* @version 1.6 (Jul 18, 2023)
* @since 1.6 (Jul 18, 2023)
*/
public final class VideoScreenCanvas extends Canvas { | {
"domain": "codereview.stackexchange",
"id": 44993,
"lm_label": null,
"lm_name": null,
"lm_q1_score": null,
"lm_q1q2_score": null,
"lm_q2_score": null,
"openwebmath_perplexity": null,
"openwebmath_score": null,
"tags": "java, compression, canvas, javafx, video",
"url": null
} |
java, compression, canvas, javafx, video
public static final int VIDEO_SCREEN_CANVAS_WIDTH = 1200;
public static final int VIDEO_SCREEN_CANVAS_HEIGHT = 800;
private static final int CIRCLE_VIDEO_SHAPE_RADIUS = 100;
private final GraphicsContext graphicsContext;
private final CircleVideoShape circleVideoShape =
new CircleVideoShape(
VIDEO_SCREEN_CANVAS_WIDTH,
VIDEO_SCREEN_CANVAS_HEIGHT,
CIRCLE_VIDEO_SHAPE_RADIUS);
private final int matrixWidth;
private final int matrixHeight;
public VideoScreenCanvas() {
super(VIDEO_SCREEN_CANVAS_WIDTH, VIDEO_SCREEN_CANVAS_HEIGHT);
this.matrixWidth = VIDEO_SCREEN_CANVAS_WIDTH;
this.matrixHeight = VIDEO_SCREEN_CANVAS_HEIGHT;
this.graphicsContext = getGraphicsContext2D();
clear();
paintCircleVideoShape();
}
public void clear() {
graphicsContext.setFill(Color.WHITE);
graphicsContext.fillRect(0, 0, matrixWidth, matrixHeight);
}
public void paintCircleVideoShape() {
graphicsContext.setFill(Color.BLACK);
graphicsContext.fillOval(
circleVideoShape.getCenterX() - circleVideoShape.getRadius(),
circleVideoShape.getCenterY() - circleVideoShape.getRadius(),
circleVideoShape.getRadius() * 2,
circleVideoShape.getRadius() * 2);
}
public void drawFrame(Image image) {
graphicsContext.drawImage(image, 0.0, 0.0);
}
public Image convertFramePixelsToImage(Color[][] framePixels) {
WritableImage raster =
new WritableImage(
framePixels[0].length,
framePixels.length);
PixelWriter pixelWriter = raster.getPixelWriter();
for (int y = 0; y < framePixels.length; y++) {
for (int x = 0; x < framePixels[0].length; x++) { | {
"domain": "codereview.stackexchange",
"id": 44993,
"lm_label": null,
"lm_name": null,
"lm_q1_score": null,
"lm_q1q2_score": null,
"lm_q2_score": null,
"openwebmath_perplexity": null,
"openwebmath_score": null,
"tags": "java, compression, canvas, javafx, video",
"url": null
} |
java, compression, canvas, javafx, video
for (int x = 0; x < framePixels[0].length; x++) {
pixelWriter.setColor(x, y, framePixels[y][x]);
}
}
return raster;
}
public CircleVideoShape getCircleVideoShape() {
return circleVideoShape;
}
} | {
"domain": "codereview.stackexchange",
"id": 44993,
"lm_label": null,
"lm_name": null,
"lm_q1_score": null,
"lm_q1q2_score": null,
"lm_q2_score": null,
"openwebmath_perplexity": null,
"openwebmath_score": null,
"tags": "java, compression, canvas, javafx, video",
"url": null
} |
java, compression, canvas, javafx, video
com.github.coderodde.compression.video.app.VideoCompressionApp.java:
package com.github.coderodde.compression.video.app;
import com.github.coderodde.compression.util.VideoScreenCanvas;
import javafx.event.EventHandler;
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.Alert;
import javafx.scene.control.Alert.AlertType;
import javafx.scene.input.MouseEvent;
import javafx.scene.layout.StackPane;
import javafx.stage.Stage;
public final class VideoCompressionApp extends Application {
static final int FRAMES_PER_SECOND = 25;
static final int VIDEO_DURATION_SECONDS = 10;
public static void main(String[] args) {
launch(args);
} | {
"domain": "codereview.stackexchange",
"id": 44993,
"lm_label": null,
"lm_name": null,
"lm_q1_score": null,
"lm_q1q2_score": null,
"lm_q2_score": null,
"openwebmath_perplexity": null,
"openwebmath_score": null,
"tags": "java, compression, canvas, javafx, video",
"url": null
} |
java, compression, canvas, javafx, video
@Override
public void start(Stage stage) throws Exception {
stage.setTitle("VideoCompressionApp 1.6 - by coderodde");
showBeginRecordingHint();
VideoScreenCanvas videoScreenCanvas = new VideoScreenCanvas();
videoScreenCanvas.paintCircleVideoShape();
EventHandler<MouseEvent> mouseEventHandler = new EventHandler<MouseEvent>() {
@Override
public void handle(MouseEvent mouseEvent) {
int x = (int) mouseEvent.getX();
int y = (int) mouseEvent.getY();
videoScreenCanvas.clear();
videoScreenCanvas.getCircleVideoShape().setCenterX(x);
videoScreenCanvas.getCircleVideoShape().setCenterY(y);
videoScreenCanvas.paintCircleVideoShape();
}
};
videoScreenCanvas.addEventHandler(
MouseEvent.MOUSE_DRAGGED,
mouseEventHandler);
stage.setResizable(false);
StackPane root = new StackPane();
root.getChildren().add(videoScreenCanvas);
stage.setScene(new Scene(root));
stage.show();
VideoRecordingThread videoRecordingThreadNoCompression =
new VideoRecordingThread(
videoScreenCanvas,
VideoRecordingThread
.VideoCompressionAlgorithm
.NO_COMPRESSION);
VideoRecordingThread videoRecordingThreadNaiveCompression =
new VideoRecordingThread(
videoScreenCanvas,
VideoRecordingThread
.VideoCompressionAlgorithm
.NAIVE_COMPRESSOR);
// Start recording.
videoRecordingThreadNoCompression.start();
videoRecordingThreadNaiveCompression.start(); | {
"domain": "codereview.stackexchange",
"id": 44993,
"lm_label": null,
"lm_name": null,
"lm_q1_score": null,
"lm_q1q2_score": null,
"lm_q2_score": null,
"openwebmath_perplexity": null,
"openwebmath_score": null,
"tags": "java, compression, canvas, javafx, video",
"url": null
} |
java, compression, canvas, javafx, video
videoRecordingThreadNaiveCompression.start();
VideoCoordinatorThread videoCoordinatorThread =
new VideoCoordinatorThread(
videoScreenCanvas,
videoRecordingThreadNoCompression,
videoRecordingThreadNaiveCompression);
videoCoordinatorThread.start();
}
private static void showBeginRecordingHint() {
Alert beginInfoAlert = new Alert(AlertType.INFORMATION);
beginInfoAlert.setTitle("Beginning recording");
beginInfoAlert.setHeaderText(
"Press OK and you will have 10 seconds to record the video.");
beginInfoAlert.setContentText(
"During the 10 seconds of recording, you can move " +
"the black circle by dragging it with the mouse.");
beginInfoAlert.showAndWait();
}
} | {
"domain": "codereview.stackexchange",
"id": 44993,
"lm_label": null,
"lm_name": null,
"lm_q1_score": null,
"lm_q1q2_score": null,
"lm_q2_score": null,
"openwebmath_perplexity": null,
"openwebmath_score": null,
"tags": "java, compression, canvas, javafx, video",
"url": null
} |
java, compression, canvas, javafx, video
com.github.coderodde.compression.video.app.VideoCoordinatorThread.java:
package com.github.coderodde.compression.video.app;
import com.github.coderodde.compression.util.Utils;
import com.github.coderodde.compression.util.VideoScreenCanvas;
import javafx.application.Platform;
import javafx.scene.control.Alert;
import javafx.scene.control.Alert.AlertType; | {
"domain": "codereview.stackexchange",
"id": 44993,
"lm_label": null,
"lm_name": null,
"lm_q1_score": null,
"lm_q1q2_score": null,
"lm_q2_score": null,
"openwebmath_perplexity": null,
"openwebmath_score": null,
"tags": "java, compression, canvas, javafx, video",
"url": null
} |
java, compression, canvas, javafx, video
/**
* This thread is a fast drop-in for coordinating the playback threads.
*
* @author Rodion "rodde" Efremov
* @version 1.6 (Jul
*/
public final class VideoCoordinatorThread extends Thread {
private static final long ITERATION_SLEEP_DURATION = 100L;
private final VideoScreenCanvas videoScreenCanvas;
private final VideoRecordingThread nonCompressiveVideoRecordingThread;
private final VideoRecordingThread naiveCompressingVideoRecordingThread;
public VideoCoordinatorThread(
VideoScreenCanvas videoScreenCanvas,
VideoRecordingThread nonCompressiveVideoRecordingThread,
VideoRecordingThread naiveCompressingVideoRecordingThread) {
this.videoScreenCanvas = videoScreenCanvas;
this.nonCompressiveVideoRecordingThread =
nonCompressiveVideoRecordingThread;
this.naiveCompressingVideoRecordingThread =
naiveCompressingVideoRecordingThread;
}
@Override
public void run() {
while (nonCompressiveVideoRecordingThread.isRunning() ||
naiveCompressingVideoRecordingThread.isRunning()) {
Utils.sleep(ITERATION_SLEEP_DURATION);
}
Platform.runLater(() -> {
Alert alert = new Alert(AlertType.INFORMATION);
alert.setTitle("Before playback");
alert.setHeaderText(
"After pressing OK, a recording via non-compressive " +
"recording starts.");
alert.setContentText("Press OK, to view non-compressed video.");
alert.showAndWait();
});
VideoPlaybackThread nonCompressiveVideoPlaybackThread =
new VideoPlaybackThread(
videoScreenCanvas,
VideoRecordingThread.VideoCompressionAlgorithm.NO_COMPRESSION,
nonCompressiveVideoRecordingThread.getBitArrayBuilder()); | {
"domain": "codereview.stackexchange",
"id": 44993,
"lm_label": null,
"lm_name": null,
"lm_q1_score": null,
"lm_q1q2_score": null,
"lm_q2_score": null,
"openwebmath_perplexity": null,
"openwebmath_score": null,
"tags": "java, compression, canvas, javafx, video",
"url": null
} |
java, compression, canvas, javafx, video
nonCompressiveVideoRecordingThread.getBitArrayBuilder());
nonCompressiveVideoPlaybackThread.start();
try {
nonCompressiveVideoPlaybackThread.join();
} catch (InterruptedException ex) {
}
Platform.runLater(() -> {
Alert alert = new Alert(AlertType.INFORMATION);
alert.setTitle("Before playback");
alert.setHeaderText(
"After pressing OK, a recording via naively-compressed " +
"recording starts.");
alert.setContentText(
"Press OK, to view the video with naive compressor.");
// REVIEW REQUEST: How to make the showAndWait() block this thread?
alert.showAndWait();
});
VideoPlaybackThread naiveCompressorVideoPlaybackThread =
new VideoPlaybackThread(
videoScreenCanvas,
VideoRecordingThread.VideoCompressionAlgorithm.NO_COMPRESSION,
nonCompressiveVideoRecordingThread.getBitArrayBuilder());
naiveCompressorVideoPlaybackThread.start();
try {
naiveCompressorVideoPlaybackThread.join();
} catch (InterruptedException ex) {
}
}
} | {
"domain": "codereview.stackexchange",
"id": 44993,
"lm_label": null,
"lm_name": null,
"lm_q1_score": null,
"lm_q1q2_score": null,
"lm_q2_score": null,
"openwebmath_perplexity": null,
"openwebmath_score": null,
"tags": "java, compression, canvas, javafx, video",
"url": null
} |
java, compression, canvas, javafx, video
com.github.coderodde.compression.video.app.VideoPlaybackThread.java:
package com.github.coderodde.compression.video.app;
import com.github.coderodde.compression.util.BitArrayBuilder;
import com.github.coderodde.compression.util.Utils;
import com.github.coderodde.compression.util.VideoScreenCanvas;
import static com.github.coderodde.compression.video.app.VideoRecordingThread.VideoCompressionAlgorithm.*;
import javafx.scene.paint.Color; | {
"domain": "codereview.stackexchange",
"id": 44993,
"lm_label": null,
"lm_name": null,
"lm_q1_score": null,
"lm_q1q2_score": null,
"lm_q2_score": null,
"openwebmath_perplexity": null,
"openwebmath_score": null,
"tags": "java, compression, canvas, javafx, video",
"url": null
} |
java, compression, canvas, javafx, video
/**
* This class implements the video playback thread.
*
* @author Rodion "rodde" Efremov
* @version 1.6 (Jul 20, 2023)
* @since 1.6 (Jul 20, 2023)
*/
public final class VideoPlaybackThread extends Thread {
private final VideoScreenCanvas videoScreenCanvas;
private final VideoRecordingThread.VideoCompressionAlgorithm algorithm;
private final BitArrayBuilder bitArrayBuilder;
private final Color[][] framePixels =
new Color[VideoScreenCanvas.VIDEO_SCREEN_CANVAS_HEIGHT]
[VideoScreenCanvas.VIDEO_SCREEN_CANVAS_WIDTH];
public VideoPlaybackThread(
VideoScreenCanvas videoScreenCanvas,
VideoRecordingThread.VideoCompressionAlgorithm algorithm,
BitArrayBuilder bitArrayBuilder) {
this.videoScreenCanvas = videoScreenCanvas;
this.algorithm = algorithm;
this.bitArrayBuilder = bitArrayBuilder;
}
@Override
public void run() {
switch (algorithm) {
case NO_COMPRESSION:
playbackWithNoCompression();
return;
case NAIVE_COMPRESSOR:
playbackWithNaiveCompressor();
return;
default:
throw new IllegalStateException(
"Unknown playback algorithm: " + algorithm);
}
}
private void playbackWithNoCompression() {
long sleepDuration = 1000L / VideoCompressionApp.FRAMES_PER_SECOND;
int frameBitsStartIndex = 0;
int frameBitLength = VideoScreenCanvas.VIDEO_SCREEN_CANVAS_HEIGHT *
VideoScreenCanvas.VIDEO_SCREEN_CANVAS_WIDTH;
for (int frameIndex = 0;
frameIndex < VideoCompressionApp.FRAMES_PER_SECOND *
VideoCompressionApp.VIDEO_DURATION_SECONDS;
frameIndex++) { | {
"domain": "codereview.stackexchange",
"id": 44993,
"lm_label": null,
"lm_name": null,
"lm_q1_score": null,
"lm_q1q2_score": null,
"lm_q2_score": null,
"openwebmath_perplexity": null,
"openwebmath_score": null,
"tags": "java, compression, canvas, javafx, video",
"url": null
} |
java, compression, canvas, javafx, video
frameIndex++) {
// Load framePixels with new pixels:
loadFramePixels(frameBitsStartIndex);
draw(framePixels);
// Advance towards the next frame:
frameBitsStartIndex += frameBitLength;
Utils.sleep(sleepDuration);
}
}
private void loadFramePixels(int frameBitStartIndex) {
int bitIndex = frameBitStartIndex;
for (int y = 0; y < framePixels.length; y++) {
for (int x = 0; x < framePixels[0].length; x++, bitIndex++) {
long bit = bitArrayBuilder.readBits(bitIndex, 1);
if (bit == 1L) {
framePixels[y][x] = Color.BLACK;
} else {
framePixels[y][x] = Color.WHITE;
}
}
}
}
private void draw(Color[][] framePixels) {
videoScreenCanvas.drawFrame(
videoScreenCanvas.convertFramePixelsToImage(framePixels));
}
private void playbackWithNaiveCompressor() {
long sleepDuration = 1000L / VideoCompressionApp.FRAMES_PER_SECOND;
int frameBitLength = VideoScreenCanvas.VIDEO_SCREEN_CANVAS_HEIGHT *
VideoScreenCanvas.VIDEO_SCREEN_CANVAS_WIDTH;
// Draw the initial frame:
loadFramePixels(0);
draw(framePixels);
Color[][] previousPixels = framePixels;
BitIndexHolder bitIndexHolder = new BitIndexHolder();
bitIndexHolder.bitIndex = frameBitLength;
for (int frameIndex = 1;
frameIndex < VideoCompressionApp.FRAMES_PER_SECOND *
VideoCompressionApp.VIDEO_DURATION_SECONDS;
frameIndex++) {
// Get the next frame::
Color[][] nextPixels =
loadNextPixels( | {
"domain": "codereview.stackexchange",
"id": 44993,
"lm_label": null,
"lm_name": null,
"lm_q1_score": null,
"lm_q1q2_score": null,
"lm_q2_score": null,
"openwebmath_perplexity": null,
"openwebmath_score": null,
"tags": "java, compression, canvas, javafx, video",
"url": null
} |
java, compression, canvas, javafx, video
Color[][] nextPixels =
loadNextPixels(
previousPixels,
bitIndexHolder);
draw(nextPixels);
previousPixels = nextPixels;
Utils.sleep(sleepDuration);
}
}
private Color[][] loadNextPixels(Color[][] previousPixels,
BitIndexHolder bitIndexHolder) {
// Compute the minimum number of bits sufficient to represent the
// integer no larger than the number of pixels in a frame:
int bitsInNumberOfPixels =
Utils.computeNumberOfBitsToStore(
VideoScreenCanvas.VIDEO_SCREEN_CANVAS_HEIGHT *
VideoScreenCanvas.VIDEO_SCREEN_CANVAS_WIDTH);
// Compute the minimum number of bits sufficient to represent any valid
// pixel X-coordinate:
int bitsInXCoordinate =
Utils.computeNumberOfBitsToStore(
VideoScreenCanvas.VIDEO_SCREEN_CANVAS_WIDTH);
// Compute the minimum number of bits sufficient to represent any valid
// pixel Y-coordinate:
int bitsInYCoordinate =
Utils.computeNumberOfBitsToStore(
VideoScreenCanvas.VIDEO_SCREEN_CANVAS_HEIGHT);
// Read the number of pixels that changed between the previous and
// next frames:
int numberOfChangedPixels =
(int) bitArrayBuilder.readBits(
bitIndexHolder.bitIndex,
bitsInNumberOfPixels);
bitIndexHolder.bitIndex += bitsInNumberOfPixels;
Color[][] nextPixels =
new Color[VideoScreenCanvas.VIDEO_SCREEN_CANVAS_HEIGHT]
[VideoScreenCanvas.VIDEO_SCREEN_CANVAS_WIDTH];
for (int pixelIndex = 0;
pixelIndex < numberOfChangedPixels; | {
"domain": "codereview.stackexchange",
"id": 44993,
"lm_label": null,
"lm_name": null,
"lm_q1_score": null,
"lm_q1q2_score": null,
"lm_q2_score": null,
"openwebmath_perplexity": null,
"openwebmath_score": null,
"tags": "java, compression, canvas, javafx, video",
"url": null
} |
java, compression, canvas, javafx, video
for (int pixelIndex = 0;
pixelIndex < numberOfChangedPixels;
pixelIndex++) {
// Read the X-coordinate of the pixel that changed between previous
// and next frames:
int x =
(int) bitArrayBuilder.readBits(
bitIndexHolder.bitIndex,
bitsInXCoordinate);
// Advance towards the Y-coordinate:
bitIndexHolder.bitIndex += bitsInXCoordinate;
// Read the Y-coordinate of the pixel that changed between previous
// and next frames:
int y =
(int) bitArrayBuilder.readBits(
bitIndexHolder.bitIndex,
bitsInYCoordinate);
// Advance towards the next pixel:
bitIndexHolder.bitIndex += bitsInYCoordinate;
Color previousPixelColor = previousPixels[y][x];
Color nextPixelColor = flipColor(previousPixelColor);
nextPixels[y][x] = nextPixelColor;
}
return nextPixels;
}
private static Color flipColor(Color color) {
return color == Color.WHITE ? Color.BLACK : Color.WHITE;
}
private static class BitIndexHolder {
int bitIndex;
}
} | {
"domain": "codereview.stackexchange",
"id": 44993,
"lm_label": null,
"lm_name": null,
"lm_q1_score": null,
"lm_q1q2_score": null,
"lm_q2_score": null,
"openwebmath_perplexity": null,
"openwebmath_score": null,
"tags": "java, compression, canvas, javafx, video",
"url": null
} |
java, compression, canvas, javafx, video
com.github.coderodde.compression.video.app.VideoRecordingThread.java:
package com.github.coderodde.compression.video.app;
import com.github.coderodde.compression.util.BitArrayBuilder;
import com.github.coderodde.compression.util.PixelColor;
import com.github.coderodde.compression.util.Utils;
import com.github.coderodde.compression.util.Utils.SleepDuration;
import com.github.coderodde.compression.util.VideoScreenCanvas;
import java.awt.Point;
import java.util.HashSet;
import java.util.Set;
import java.util.concurrent.atomic.AtomicBoolean;
import javafx.application.Platform; | {
"domain": "codereview.stackexchange",
"id": 44993,
"lm_label": null,
"lm_name": null,
"lm_q1_score": null,
"lm_q1q2_score": null,
"lm_q2_score": null,
"openwebmath_perplexity": null,
"openwebmath_score": null,
"tags": "java, compression, canvas, javafx, video",
"url": null
} |
java, compression, canvas, javafx, video
public final class VideoRecordingThread extends Thread {
public static enum VideoCompressionAlgorithm {
NO_COMPRESSION,
NAIVE_COMPRESSOR;
}
private final int framesToRecord;
private final VideoScreenCanvas videoScreenCanvas;
private final VideoCompressionAlgorithm compressionAlgorithm;
private BitArrayBuilder bitArrayBuilder;
private final AtomicBoolean isRunning = new AtomicBoolean(true);
public VideoRecordingThread(
VideoScreenCanvas videoScreenCanvas,
VideoCompressionAlgorithm compressionAlgorithm) {
this.videoScreenCanvas = videoScreenCanvas;
this.framesToRecord = VideoCompressionApp.FRAMES_PER_SECOND *
VideoCompressionApp.VIDEO_DURATION_SECONDS;
this.compressionAlgorithm = compressionAlgorithm;
}
public BitArrayBuilder getBitArrayBuilder() {
return this.bitArrayBuilder;
}
public boolean isRunning() {
return isRunning.get();
}
@Override
public void run() {
switch (compressionAlgorithm) {
case NO_COMPRESSION:
recordWithNoCompression();
isRunning.set(false);
return;
case NAIVE_COMPRESSOR:
recordWithNaiveCompression();
isRunning.set(false);
return;
}
throw new IllegalStateException(
"Unknown compression algorithm: " + compressionAlgorithm);
}
private void recordWithNoCompression() {
SleepDuration sleepDuration =
Utils.getFrameSleepDuration(
VideoCompressionApp.FRAMES_PER_SECOND); | {
"domain": "codereview.stackexchange",
"id": 44993,
"lm_label": null,
"lm_name": null,
"lm_q1_score": null,
"lm_q1q2_score": null,
"lm_q2_score": null,
"openwebmath_perplexity": null,
"openwebmath_score": null,
"tags": "java, compression, canvas, javafx, video",
"url": null
} |
java, compression, canvas, javafx, video
int bitArrayBuilderCapacity =
VideoCompressionApp.FRAMES_PER_SECOND *
VideoCompressionApp.VIDEO_DURATION_SECONDS *
VideoScreenCanvas.VIDEO_SCREEN_CANVAS_WIDTH *
VideoScreenCanvas.VIDEO_SCREEN_CANVAS_HEIGHT;
bitArrayBuilder = new BitArrayBuilder(bitArrayBuilderCapacity);
for (int frameIndex = 0;
frameIndex < framesToRecord;
frameIndex++) {
Platform.runLater(() -> {
videoScreenCanvas.clear();
videoScreenCanvas.paintCircleVideoShape();
});
Utils.sleep(sleepDuration);
PixelColor[][] pixelMatrix =
videoScreenCanvas
.getCircleVideoShape()
.getColorMatrix(); | {
"domain": "codereview.stackexchange",
"id": 44993,
"lm_label": null,
"lm_name": null,
"lm_q1_score": null,
"lm_q1q2_score": null,
"lm_q2_score": null,
"openwebmath_perplexity": null,
"openwebmath_score": null,
"tags": "java, compression, canvas, javafx, video",
"url": null
} |
java, compression, canvas, javafx, video
for (PixelColor[] pixelMatrixRow : pixelMatrix) {
for (PixelColor pixelColor : pixelMatrixRow) {
bitArrayBuilder.appendBits(
pixelColor == PixelColor.WHITE ? 0L : 1L,
1);
}
}
}
System.out.println(
"Bits in no compression bit array: " + bitArrayBuilder.size());
}
private void recordWithNaiveCompression() {
SleepDuration sleepDuration =
Utils.getFrameSleepDuration(
VideoCompressionApp.FRAMES_PER_SECOND);
bitArrayBuilder = new BitArrayBuilder();
// Process the first frame:
PixelColor[][] previousPixelMatrix = processFirstFrame();
Utils.sleep(sleepDuration);
for (int frameIndex = 1; frameIndex < framesToRecord; frameIndex++) {
Platform.runLater(() -> {
videoScreenCanvas.clear();
videoScreenCanvas.paintCircleVideoShape();
});
Utils.sleep(sleepDuration);
PixelColor[][] currentPixelMatrix =
videoScreenCanvas.getCircleVideoShape().getColorMatrix();
loadBits(previousPixelMatrix, currentPixelMatrix);
previousPixelMatrix = currentPixelMatrix;
}
System.out.println(
"Bits in naive compressor bit array: " +
bitArrayBuilder.size());
}
private void loadBits(PixelColor[][] previousPixelMatrix,
PixelColor[][] currentPixelMatrix) {
int matrixHeight = previousPixelMatrix.length;
int matrixWidth = previousPixelMatrix[0].length;
int matrixYBitLength =
Utils.computeNumberOfBitsToStore(matrixHeight);
int matrixXBitLength = | {
"domain": "codereview.stackexchange",
"id": 44993,
"lm_label": null,
"lm_name": null,
"lm_q1_score": null,
"lm_q1q2_score": null,
"lm_q2_score": null,
"openwebmath_perplexity": null,
"openwebmath_score": null,
"tags": "java, compression, canvas, javafx, video",
"url": null
} |
java, compression, canvas, javafx, video
int matrixXBitLength =
Utils.computeNumberOfBitsToStore(matrixWidth);
Set<Point> changedPixelPoints = new HashSet<>();
for (int y = 0; y < previousPixelMatrix.length; y++) {
for (int x = 0; x < previousPixelMatrix[0].length; x++) {
PixelColor previousPixelColor = previousPixelMatrix[y][x];
PixelColor currentPixelColor = currentPixelMatrix[y][x];
if (previousPixelColor != currentPixelColor) {
changedPixelPoints.add(new Point(x, y));
}
}
}
int changedPixelPointsBitLength =
Utils.computeNumberOfBitsToStore(
VideoScreenCanvas.VIDEO_SCREEN_CANVAS_WIDTH *
VideoScreenCanvas.VIDEO_SCREEN_CANVAS_HEIGHT);
bitArrayBuilder.appendBits(changedPixelPoints.size(),
changedPixelPointsBitLength);
for (Point point : changedPixelPoints) {
bitArrayBuilder.appendBits(point.x, matrixXBitLength);
bitArrayBuilder.appendBits(point.y, matrixYBitLength);
}
}
private PixelColor[][] processFirstFrame() {
PixelColor[][] pixelMatrix =
videoScreenCanvas.getCircleVideoShape().getColorMatrix();
for (int y = 0; y < pixelMatrix.length; y++) {
for (int x = 0; x < pixelMatrix[0].length; x++) {
if (pixelMatrix[y][x].equals(PixelColor.WHITE)) {
bitArrayBuilder.appendBits(0L, 1);
} else {
bitArrayBuilder.appendBits(1L, 1);
}
}
}
return pixelMatrix;
}
} | {
"domain": "codereview.stackexchange",
"id": 44993,
"lm_label": null,
"lm_name": null,
"lm_q1_score": null,
"lm_q1q2_score": null,
"lm_q2_score": null,
"openwebmath_perplexity": null,
"openwebmath_score": null,
"tags": "java, compression, canvas, javafx, video",
"url": null
} |
java, compression, canvas, javafx, video
Typical output
After the recording is done, both the recording threads output the number of bits it took to store the entire video. Looks like this:
Bits in no compression bit array: 240000000
Bits in naive compressor bit array: 27451650
GitHub
The entire repository is here.
Answer: Some improvements:
VideoCompressionApp class:
This piece of code can be replace with something more elegant:
EventHandler<MouseEvent> mouseEventHandler = new EventHandler<MouseEvent>() {
@Override
public void handle(MouseEvent mouseEvent) {
int x = (int) mouseEvent.getX();
int y = (int) mouseEvent.getY();
videoScreenCanvas.clear();
videoScreenCanvas.getCircleVideoShape().setCenterX(x);
videoScreenCanvas.getCircleVideoShape().setCenterY(y);
videoScreenCanvas.paintCircleVideoShape();
}
};
You can replace with lambda:
EventHandler<MouseEvent> mouseEventHandler = mouseEvent -> {
int x = (int) mouseEvent.getX();
int y = (int) mouseEvent.getY();
videoScreenCanvas.clear();
videoScreenCanvas.getCircleVideoShape().setCenterX(x);
videoScreenCanvas.getCircleVideoShape().setCenterY(y);
videoScreenCanvas.paintCircleVideoShape();
};
Instead of duplicate code here:
VideoRecordingThread videoRecordingThreadNoCompression =
new VideoRecordingThread(
videoScreenCanvas,
VideoRecordingThread
.VideoCompressionAlgorithm
.NO_COMPRESSION);
VideoRecordingThread videoRecordingThreadNaiveCompression =
new VideoRecordingThread(
videoScreenCanvas,
VideoRecordingThread
.VideoCompressionAlgorithm
.NAIVE_COMPRESSOR); | {
"domain": "codereview.stackexchange",
"id": 44993,
"lm_label": null,
"lm_name": null,
"lm_q1_score": null,
"lm_q1q2_score": null,
"lm_q2_score": null,
"openwebmath_perplexity": null,
"openwebmath_score": null,
"tags": "java, compression, canvas, javafx, video",
"url": null
} |
java, compression, canvas, javafx, video
You can extract a method:
private VideoRecordingThread createVideoRecordingThread(VideoCompressionAlgorithm compressionAlogrithm)
For VideoRecordingThread class:
public static enum VideoCompressionAlgorithm {
NO_COMPRESSION,
NAIVE_COMPRESSOR;
}
static is redundant here; nested enum types are implicitly static.
Since you are working with JDK20 (just saw it in your pom.xml),
you can convert switch/case to the more elegant switch/case provided by JDK17.
So instead of:
@Override
public void run() {
switch (compressionAlgorithm) {
case NO_COMPRESSION:
recordWithNoCompression();
isRunning.set(false);
return;
case NAIVE_COMPRESSOR:
recordWithNaiveCompression();
isRunning.set(false);
return;
}
throw new IllegalStateException(
"Unknown compression algorithm: " + compressionAlgorithm);
}
better to enhance it with:
@Override
public void run() {
switch (compressionAlgorithm) {
case NO_COMPRESSION -> {
recordWithNoCompression();
isRunning.set(false);
return;
}
case NAIVE_COMPRESSOR -> {
recordWithNaiveCompression();
isRunning.set(false);
return;
}
}
throw new IllegalStateException(
"Unknown compression algorithm: " + compressionAlgorithm);
}
in the term of pretty switch case in JDK20.
Look at BitArrayBuilder class
Instead of your getDataByte(), I wrote my own as:
private byte getDataByte(int byteIndex) {
long longData = bitArray[byteIndex / Long.BYTES];
byteIndex %= Long.BYTES; | {
"domain": "codereview.stackexchange",
"id": 44993,
"lm_label": null,
"lm_name": null,
"lm_q1_score": null,
"lm_q1q2_score": null,
"lm_q2_score": null,
"openwebmath_perplexity": null,
"openwebmath_score": null,
"tags": "java, compression, canvas, javafx, video",
"url": null
} |
java, compression, canvas, javafx, video
return switch (byteIndex) {
case 0 -> (byte) (longData);
case 1 -> (byte) ((longData >> 8) & 0xFF);
case 2 -> (byte) ((longData >> 16) & 0xFF);
case 3 -> (byte) ((longData >> 24) & 0xFF);
case 4 -> (byte) ((longData >> 32) & 0xFF);
case 5 -> (byte) ((longData >> 40) & 0xFF);
case 6 -> (byte) ((longData >> 48) & 0xFF);
case 7 -> (byte) ((longData >> 56) & 0xFF);
default -> throw new IllegalStateException("Should not get here ever.");
};
}
Utils class:
Since this class is static, you must declare a private constructor to force any instantiation of this class to be a compilation error.
You have duplicate code here:
public static void sleep(long milliseconds, int nanoseconds) {
try {
Thread.sleep(milliseconds, nanoseconds);
} catch (InterruptedException ex) {
}
}
public static void sleep(SleepDuration sleepDuration) {
try {
Thread.sleep(sleepDuration.millisecondsPart,
sleepDuration.nanosecondsPart);
} catch (InterruptedException ex) {
}
}
This could be:
public static void sleep(long milliseconds, int nanoseconds) {
try {
Thread.sleep(milliseconds, nanoseconds);
} catch (InterruptedException ex) {
}
}
public static void sleep(SleepDuration sleepDuration) {
sleep(sleepDuration.millisecondsPart, sleepDuration.nanosecondsPart);
}
You are catching errors with no handling in the catch part; this is not best practice. At least print something.
PixelColor class:
You have redundant semicolon after Black type. | {
"domain": "codereview.stackexchange",
"id": 44993,
"lm_label": null,
"lm_name": null,
"lm_q1_score": null,
"lm_q1q2_score": null,
"lm_q2_score": null,
"openwebmath_perplexity": null,
"openwebmath_score": null,
"tags": "java, compression, canvas, javafx, video",
"url": null
} |
c++, beginner, multithreading, concurrency, producer-consumer
Title: Packet generation and consumption
Question: I have the following simplification of a program which consists of 2 threads. One thread pushes packets to the back of a deque while another waits for user input before performing a "heavy" operation on the current deque (Here, we just look for the maximum id).
#include <iostream>
#include <thread>
#include <random>
#include <chrono>
#include <deque>
#include <string>
#include <mutex>
using namespace std;
struct Packet{
int id;
int size;
};
mutex deque_mutex;
deque<shared_ptr<Packet> > packet_deque;
void gen_packet(Packet* packet){
// generate packets
// packet size is 1-100 bytes
// packet id is 0-1000
random_device rd;
mt19937 gen(rd());
uniform_int_distribution<> size_dist(1, 100);
uniform_int_distribution<> id_dist(0, 1000);
int size = size_dist(gen);
int id = id_dist(gen);
packet->size = size;
packet->id = id;
}
void packet_monitor(){
// Gets a packet every 100th of a second
// Add it to the deque
// If the deque is full, remove the oldest packet
// A deque is full if it has 1000 packets
while(true){
shared_ptr<Packet> packet = make_shared<Packet>();
gen_packet(packet.get());
unique_lock<mutex> lock(deque_mutex);
if(packet_deque.size() == 1000){
packet_deque.pop_front();
}
packet_deque.push_back(packet);
lock.unlock();
this_thread::sleep_for(chrono::milliseconds(10));
}
} | {
"domain": "codereview.stackexchange",
"id": 44994,
"lm_label": null,
"lm_name": null,
"lm_q1_score": null,
"lm_q1q2_score": null,
"lm_q2_score": null,
"openwebmath_perplexity": null,
"openwebmath_score": null,
"tags": "c++, beginner, multithreading, concurrency, producer-consumer",
"url": null
} |
c++, beginner, multithreading, concurrency, producer-consumer
void operate(){
// Listens for a key stroke
// It then looks for the packet with the biggest id
while(true){
string input;
getline(std::cin, input);
if(!input.empty()){
int max_id = 0;
int max_index_id = 0;
unique_lock<mutex> lock(deque_mutex);
deque<shared_ptr<Packet> > packet_deque_copy(packet_deque);
lock.unlock();
for(int i = 0; i < packet_deque_copy.size(); i++){
if(packet_deque_copy[i]->id > max_id){
max_id = packet_deque_copy[i]->id;
max_index_id = i;
}
}
cout << "Max id: " << max_id << " at " << max_index_id << "\n";
}
}
}
int main(){
thread packet_monitor_thread(packet_monitor);
thread operate_thread(operate);
packet_monitor_thread.join();
operate_thread.join();
return 0;
}
I am not very familiar with cpp nor with concurrency, so I have some questions about the best way to solve this
Do I have any memory leaks here? I am assuming the shared_ptr takes care of freeing the memories for packets that are deleted from the deque. Is that correct?
I use a unique_lock here to try to tackle the potential deadlock that might arise from an exception being thrown inbetween the lock and unlock. Is there a more cpp way of doing this?
I think that the locking and unlocking for every packet is a bit overkill. I can buffer 10 at a time and then push those. What are some of the implications of locking/unlocking so quickly?
Here, I don't need to wait for a packet to come, but in the actual implementation I block until there is another packet available. Hence, I have both a blocking operation while waiting for input from the user as well as blocking for a packet to arrive. Am I introducing any potential deadlocks, or is there a better way to think about this? | {
"domain": "codereview.stackexchange",
"id": 44994,
"lm_label": null,
"lm_name": null,
"lm_q1_score": null,
"lm_q1q2_score": null,
"lm_q2_score": null,
"openwebmath_perplexity": null,
"openwebmath_score": null,
"tags": "c++, beginner, multithreading, concurrency, producer-consumer",
"url": null
} |
c++, beginner, multithreading, concurrency, producer-consumer
Answer: General review
Please don't using namespace std;. That invites conflict with identifiers (and perhaps even changes in behaviour when compiled with later versions of standard library).
We include <atomic> and <string> but never use anything from them.
gen_packet() seems to assume its argument is never null - it's probably clearer to accept a reference instead of a pointer.
It certainly shouldn't be creating a new std::random_device and generator every time it is called. We should do that just once:
static std::mt19937 gen{std::random_device{}()};
packet_monitor() never leaves its loop. This means that wait()ing for it will never return.
I don't like hardcoding the specific size (1000) in there - why shouldn't we be able to create one with larger size?
Instead of writing lock.unlock(), I find it clearer to use scope for locks:
{
std::lock_guard<std::mutex> _{deque_mutex};
if (packet_deque.size() == 1000) [[likely]] {
packet_deque.pop_front();
}
packet_deque.emplace_back(std::move(packet));
}
(I've added a couple of small optimisations in there, too.)
operate() never checks the state of std::cin after calling std::getline(). So we busy-loop when input is disconnected.
The for loop uses the wrong type for i. Since we're comparing to a std::size_t, prefer to use the same type for i.
Instead of hand-coding the loop, we could be using std::max_element(), though that might cost more if we really do need the index (as we'd need std::distance() to derive that). We could create a std::ranges::enumerate_view to avoid that.
main() spawns two threads and waits for them both. That's three threads in total, but one of them is just waiting. Instead, we could call operate() directly from main(). And we could use std::jthread so that end of scope waits for completion.
Your questions | {
"domain": "codereview.stackexchange",
"id": 44994,
"lm_label": null,
"lm_name": null,
"lm_q1_score": null,
"lm_q1q2_score": null,
"lm_q2_score": null,
"openwebmath_perplexity": null,
"openwebmath_score": null,
"tags": "c++, beginner, multithreading, concurrency, producer-consumer",
"url": null
} |
c++, beginner, multithreading, concurrency, producer-consumer
Your questions
I see no leaks. With no naked new or any C Library allocations, and no calls to std::unique_ptr::release(), every object is accounted for. That assessment is corroborated by a few runs under Valgrind.
Scoped locks such as std::unique_lock or std::lock_guard are entirely appropriate here. I prefer not to unlock() them if avoidable, as mentioned above.
We could buffer input, and push in batches, but only if it's acceptable for the reader to get stale data. For most platforms, lock acquisition is an important performance consideration, and much work has been put into optimising them, particularly in low-contention scenarios such as this. So I wouldn't be concerned about the overhead unless profiling identifies it as a problem.
There should be no starvation as long as we don't hold the lock during the blocking operations. There cannot be deadlock if we only ever hold one lock at a time.
Performance considerations
Use of a std::deque is sub-optimal here, as we never need more than 1000 elements. What we have implemented is a ring buffer, and we can simply overwrite old values with the new ones as we go. Then we never need to allocate and release storage (in push_back() and pop_front()).
Since we're storing (smart) pointers, we have a natural null value for not-yet initialised ring-buffer elements, so we only need to track the insert position, and just filter nulls out when reading.
Suggested code
Here, I create a ring buffer, and move the mutex inside it, giving atomic functions to add a value and to take a copy of the contents.
I also avoid global variables, and use std::jthread to simplify the main().
#include <algorithm>
#include <chrono>
#include <iostream>
#include <iterator>
#include <mutex>
#include <random>
#include <ranges>
#include <thread>
#include <tuple>
struct Packet {
int id;
int size;
}; | {
"domain": "codereview.stackexchange",
"id": 44994,
"lm_label": null,
"lm_name": null,
"lm_q1_score": null,
"lm_q1q2_score": null,
"lm_q2_score": null,
"openwebmath_perplexity": null,
"openwebmath_score": null,
"tags": "c++, beginner, multithreading, concurrency, producer-consumer",
"url": null
} |
c++, beginner, multithreading, concurrency, producer-consumer
struct Packet {
int id;
int size;
};
template<std::size_t N>
class PacketBuffer
{
using pkt_ptr = std::shared_ptr<Packet>;
using arr_t = std::array<pkt_ptr, N>;
using iterator = arr_t::iterator;
using const_iterator = arr_t::const_iterator;
arr_t buffer = {};
iterator insert_pos = buffer.begin();
mutable std::mutex mutex = {};
public:
void emplace_back(pkt_ptr packet)
{
std::lock_guard<std::mutex> _{mutex};
*insert_pos++ = std::move(packet);
if (insert_pos == buffer.end()) {
insert_pos = buffer.begin();
}
}
auto to_vector() const
{
std::lock_guard<std::mutex> _{mutex};
const_iterator const p = insert_pos;
std::vector<pkt_ptr> result;
auto out = std::back_inserter(result);
if (*insert_pos) [[likely]] {
result.reserve(N);
// put the older data at beginning of output
std::copy(p, buffer.end(), out);
} else {
result.reserve(std::distance(buffer.begin(), p));
}
std::copy(buffer.begin(), p, out);
return result;
}
};
void gen_packet(Packet& packet)
{
// generate packets
// packet size is 1-100 bytes
// packet id is 0-1000
static std::mt19937 gen{std::random_device {}()};
static std::uniform_int_distribution size_dist{0, 100};
// static std::uniform_int_distribution id_dist{0, 1000};
static std::poisson_distribution id_dist{600};
packet.size = size_dist(gen);
packet.id = id_dist(gen);
}
template<class Buffer>
void packet_monitor(Buffer& buffer)
{
// Gets a packet every 100th of a second
// and appends it to the buffer
while (std::cin) {
auto packet = std::make_shared<Packet>();
gen_packet(*packet);
buffer.emplace_back(std::move(packet));
std::this_thread::sleep_for(std::chrono::milliseconds(10));
}
} | {
"domain": "codereview.stackexchange",
"id": 44994,
"lm_label": null,
"lm_name": null,
"lm_q1_score": null,
"lm_q1q2_score": null,
"lm_q2_score": null,
"openwebmath_perplexity": null,
"openwebmath_score": null,
"tags": "c++, beginner, multithreading, concurrency, producer-consumer",
"url": null
} |
c++, beginner, multithreading, concurrency, producer-consumer
template<class Buffer>
void operate(Buffer& buffer)
{
// Listens for a newline
// and then find the packet with the biggest id
std::string input;
while (std::getline(std::cin, input)) {
auto buf_copy = buffer.to_vector();
if (buf_copy.empty()) [[unlikely]] {
// is this really right??
std::cout << "Max id: 0 at 0\n";
} else {
auto const get_id
// get the id from an enumerated pointer to packet
= [](auto const& x){return std::get<1>(x)->id;};
auto const [max_index_id, max_element]
= *std::ranges::max_element(buf_copy | std::views::enumerate,
std::less<>{}, get_id);
std::cout << "Max id: " << max_element->id
<< " at " << max_index_id
<< '\n';
}
}
}
int main()
{
PacketBuffer<1000> ringbuf;
std::jthread packet_monitor_thread(packet_monitor<decltype(ringbuf)>,
std::ref(ringbuf));
operate(ringbuf);
} | {
"domain": "codereview.stackexchange",
"id": 44994,
"lm_label": null,
"lm_name": null,
"lm_q1_score": null,
"lm_q1q2_score": null,
"lm_q2_score": null,
"openwebmath_perplexity": null,
"openwebmath_score": null,
"tags": "c++, beginner, multithreading, concurrency, producer-consumer",
"url": null
} |
console, tic-tac-toe, kotlin
Title: TicTacToe OOP approach in Kotlin
Question: I wrote a terminal-based TicTacToe game in Kotlin to practice both Kotlin and OOP. Any feedback on structure and code would be appreciated.
Board.kt
package main.com.github.me.tictactoe
class Board {
val originalBoardConfig = listOf(
listOf("1", "2", "3"),
listOf("4", "5", "6"),
listOf("7", "8", "9")
)
val board = originalBoardConfig.map { it.toMutableList() }.toMutableList()
var boardMap = hashMapOf<String, String>()
// initialises the boardMap
init {
resetBoardMap()
}
fun resetBoardMap() {
boardMap = hashMapOf(
"1" to board[0][0],
"2" to board[0][1],
"3" to board[0][2],
"4" to board[1][0],
"5" to board[1][1],
"6" to board[1][2],
"7" to board[2][0],
"8" to board[2][1],
"9" to board[2][2]
)
}
fun getBoardMap(): MutableMap<String, String> {
return boardMap
}
fun drawBoard() {
println("Current board:\n")
for (rowIdx in 0 until 3) {
println(" ${boardMap["${rowIdx * 3 + 1}"]} | ${boardMap["${rowIdx * 3 + 2}"]} | ${boardMap["${rowIdx * 3 + 3}"]}")
if (rowIdx < 2) {
println("-----------")
}
}
println()
}
}
Turns.kt
package main.com.github.me.tictactoe
import java.util.*
class Turns(val board: Board) {
val validPositions = listOf("1", "2", "3", "4", "5", "6", "7", "8", "9")
private fun validateAndPlaceSymbol(symbol: String, position: String): Boolean {
val boardMap = board.getBoardMap()
if (boardMap[position] in validPositions) {
boardMap[position] = symbol
return true
}
return false
}
fun makeAPlay(player: Int, symbol: String): String {
val scanner = Scanner(System.`in`) | {
"domain": "codereview.stackexchange",
"id": 44995,
"lm_label": null,
"lm_name": null,
"lm_q1_score": null,
"lm_q1q2_score": null,
"lm_q2_score": null,
"openwebmath_perplexity": null,
"openwebmath_score": null,
"tags": "console, tic-tac-toe, kotlin",
"url": null
} |
console, tic-tac-toe, kotlin
fun makeAPlay(player: Int, symbol: String): String {
val scanner = Scanner(System.`in`)
while (true) {
board.drawBoard()
println("Player $player, place '$symbol' by selecting a number between 1 and 9 (or enter 'q' to quit): ")
val input = scanner.nextLine()
if (input == "q") {
println("Quitting the game.")
System.exit(0)
}
if (input.length != 1 || !input[0].isDigit()) {
println()
println("Invalid input. Please enter a single digit between 1 and 9.")
println()
continue
}
if (input in validPositions) {
if (validateAndPlaceSymbol(symbol, input)) {
return input
} else {
println()
println("Invalid position. The position has already been taken.")
println()
}
} else {
println("Invalid input. Please enter a digit between 1 and 9.")
}
}
}
fun switchPlayer(player: Int, symbol: String): Pair<Int, String> {
return when {
player == 1 && symbol == "X" -> {
Pair(2, "O")
}
else -> {
Pair(1, "X")
}
}
}
fun playAgain() {
println("Play again? (y/n)")
val scanner = Scanner(System.`in`)
while (true) {
val input = scanner.nextLine()
if (input == "n") {
println("Quitting the game.")
System.exit(0)
} else if (input == "y") {
board.resetBoardMap()
return
}
else {
println("Invalid input. Play again? (y/n)")
}
}
}
}
WinningConditions.kt
package main.com.github.me.tictactoe | {
"domain": "codereview.stackexchange",
"id": 44995,
"lm_label": null,
"lm_name": null,
"lm_q1_score": null,
"lm_q1q2_score": null,
"lm_q2_score": null,
"openwebmath_perplexity": null,
"openwebmath_score": null,
"tags": "console, tic-tac-toe, kotlin",
"url": null
} |
console, tic-tac-toe, kotlin
WinningConditions.kt
package main.com.github.me.tictactoe
class WinningConditions(val board: Board) {
private val winningCombinations = listOf(
listOf("1", "2", "3"),
listOf("4", "5", "6"),
listOf("7", "8", "9"),
listOf("1", "4", "7"),
listOf("2", "5", "8"),
listOf("3", "6", "9"),
listOf("1", "5", "9"),
listOf("3", "5", "7")
)
fun win(player: Int, symbol: String): Boolean {
val boardMap = board.getBoardMap()
for (combination in winningCombinations) {
if (combination.all { position -> boardMap[position] == symbol }) {
board.drawBoard()
println("Player $player WINS!")
return true
}
}
return false
}
}
main.kt
import main.com.github.me.tictactoe.Board
import main.com.github.me.tictactoe.Turns
import main.com.github.me.tictactoe.WinningConditions
fun main() {
println("Welcome to TicTacToe!")
val ticTacToeBoard = Board()
val turns = Turns(ticTacToeBoard)
val win = WinningConditions(ticTacToeBoard)
while (true) {
var player = 1
var symbol = "X"
var round = 0
while (round < 9) {
turns.makeAPlay(player, symbol)
if (win.win(player, symbol)) {
turns.playAgain()
break // Exit the current game loop if there's a winner
}
val playerSwitch = turns.switchPlayer(player, symbol)
player = playerSwitch.first
symbol = playerSwitch.second
round += 1
}
if (round == 9) {
ticTacToeBoard.drawBoard()
println("It's a draw.")
turns.playAgain()
}
}
} | {
"domain": "codereview.stackexchange",
"id": 44995,
"lm_label": null,
"lm_name": null,
"lm_q1_score": null,
"lm_q1q2_score": null,
"lm_q2_score": null,
"openwebmath_perplexity": null,
"openwebmath_score": null,
"tags": "console, tic-tac-toe, kotlin",
"url": null
} |
console, tic-tac-toe, kotlin
Answer: Overall the method names, variable names, indentation and use of whitespace is spot on, which makes it easy to read the code.
Enumerating all the positions is not really required, but it does show good abstract thinking and a clear way to solve the problem.
Board class
If well programmed it should be possible to use no literals in the Board, other than possibly the board dimensions. Let the computer do the counting.
There are some things going on that are not clear, such as why the identification is performed using a string. If a string has to be used then convert a counter to a string.
The Board class seems to be some kind of factory instead of a true OOP class; it only seems to have mutable state, and the entire state is made visible through getBoardMap. You could hold the board state in the Board class and then maybe build some kind of stateful (Game) object on top of it , for instance keeping in mind who's turn it is - see remarks for Turns.
Personally I'd always introduce a Position data class. Then each piece or mark can have a Position. It also allows to check if a position is on the board etc. Note that, given a width and a height you should be able to get a value of 0..8 using multiply with addition from the x and y coordinate. And similarly you can get the x and y coordinate of a number 0..8 using division with remainder!
It's always best to provide an "output" to a print statement. Maybe the game needs to be tested later, and it is hard to read anything back from a console. So providing a PrintStream parameter to drawBoard is highly recommended.
Turns class
This class name immediately raises red flags. Normally a class has a name that is a singular noun. Turns isn't anything specific, and this follows from the fact that it lacks any state. It's better to have a Game class that contains these methods but keeps state.
if it isn't possible to figure out what a class represents then there is something wrong with the design | {
"domain": "codereview.stackexchange",
"id": 44995,
"lm_label": null,
"lm_name": null,
"lm_q1_score": null,
"lm_q1q2_score": null,
"lm_q2_score": null,
"openwebmath_perplexity": null,
"openwebmath_score": null,
"tags": "console, tic-tac-toe, kotlin",
"url": null
} |
console, tic-tac-toe, kotlin
The Game class can keep state, which means that if Game#switchPlayer is called that the Pair result isn't needed, as it is possible to simply change the state of the ongoing game. That's one of the advantage of fields; it is possible to keep the amount of method arguments and results down.
Some additional counting is going on here for the valid positions. It's not clear why the map that makes up the board is not enough. It already has the strings as hashes after all.
When quitting the game don't forget to print out the final state of the game, and maybe point out a winner (i.e. the other player). Probably best to do this in a separate method, the game may be ended in multiple ways after all (.
Similar remark about checking for valid positions; that's something that should really be in a separate method. To me it makes sense to ask the board if something is a valid position.
WinningConditions class
It's a good idea to have a method or a class that checks if the game is over. Of course, a mathematical method of checking if the game has ended should be preferred; we're all programmers after all. For instance, it is possible to see that the game has rows, columns and 2 diagonals, so simply checking if these are all filled by the pieces / marks of any player would indicate that the game has been won.
In principle it is possible to have a piece that has a color, and the color matches the player. In that case only a single parameter may be required. Or zero, if the end condition simply returns an optional color of who has won. Personally I like enums better than strings; the code is using too many string arguments.
main
The main method is very readable. TicTacToe is of course a simple game, but it needs to be said that this is easy to read and no surprises seem to jump out. This is very important and shows that the design is good enough for this problem. | {
"domain": "codereview.stackexchange",
"id": 44995,
"lm_label": null,
"lm_name": null,
"lm_q1_score": null,
"lm_q1q2_score": null,
"lm_q2_score": null,
"openwebmath_perplexity": null,
"openwebmath_score": null,
"tags": "console, tic-tac-toe, kotlin",
"url": null
} |
console, tic-tac-toe, kotlin
It's always advisable to put as little gameplay itself in the main method. Generally it pays to have any program run without requiring main to be called. Generally it is also advisable to split the UI elements (in this case the console input / output) from the gameplay itself.
So given a Game (or TicTacToe!) class, the main method could be put in e.g. a Game#play method. When it is required to restart then just create a new Game instead of resetting the board. That way all the state will be reset automatically.
A for ... in ... until is also perfectly possible in Kotlin; that would be better readable than the while loop. | {
"domain": "codereview.stackexchange",
"id": 44995,
"lm_label": null,
"lm_name": null,
"lm_q1_score": null,
"lm_q1q2_score": null,
"lm_q2_score": null,
"openwebmath_perplexity": null,
"openwebmath_score": null,
"tags": "console, tic-tac-toe, kotlin",
"url": null
} |
python
Title: Improvements in how to partition the csv?
Question: I have a csv with data. There are a total number of 9 samples, each sample has multiple fits. Each fit has an associated name, chi2, degrees of freedom, variable name that was fit, and the actual values.
Out of this huge table, I'd like to only extract a handful of fits. I'd then like to get the values of the fits, and plug them into another function to get some values that I can then plot.
I have effectively resorted to creating a multi-nested list. The top most layer is the sample, followed by all the fits of said sample, followed by lists of the various parameters (fit name, fit values, etc.).
[[sample_1[fit_1[[fit_name_1][fit_value_1]][fit_2[fit_name2][fit_value_2]]]....][sample_2[...
I don't think this is the worst thing in the world, but the only way I could get this to work is....bad. I had a couple issues I couldn't really work out resulting in this mess
There are multiple fits per sample that need to be added to the list. Once you are done with one sample, this list of lists needs to then be added to the (lack of a better word) "mega_list". Except there is nothing in the csv for a clean end of one list, and a clean start to another. As such I've resorted to literally have a list for every condition. The same is true of the concentrations. Each sample has a set of concentrations. Some fits are global and use all the concentrations, some are not. So I also need a list of concentrations, with no duplicates, but the order is important. But again, I don't know how to indicate the end of one list and the start of another, so I cannot add these to the same list. As such I have separate lists for each concentration and each fit per sample. | {
"domain": "codereview.stackexchange",
"id": 44996,
"lm_label": null,
"lm_name": null,
"lm_q1_score": null,
"lm_q1q2_score": null,
"lm_q2_score": null,
"openwebmath_perplexity": null,
"openwebmath_score": null,
"tags": "python",
"url": null
} |
python
The above also has resulted in a lot of duplication. e.g. the regex filter can be combined since you are looking for the same thing for multiple samples (e.g. 'Monomer-Closed' for samples in {'L273A_2019','L273A_2020'...}. However because I couldn't cleanly indicate the start of one sample and the end of the other, I had to separate each of these into their own conditionals.
The plotting is a bit ugly. Each sample has 3 different techniques for fitting. Individual and Single Scales, these are global fits (hence looping through concentrations). And local fits (only done at a single concentration). There is a lot of reptition here as well (I'm plotting the same 3 things over and over again per sample), but again, I'm unable to get the code any cleaner than it currently is.
Finally, and this is a small thing made difficult due to how ugly and poorly I've set everything. I'd like to connect the dots of my scatter plots, but because the concentrations are not sorted, the connection looks terrible. | {
"domain": "codereview.stackexchange",
"id": 44996,
"lm_label": null,
"lm_name": null,
"lm_q1_score": null,
"lm_q1q2_score": null,
"lm_q2_score": null,
"openwebmath_perplexity": null,
"openwebmath_score": null,
"tags": "python",
"url": null
} |
python
It should be noted while I could just say based on this csv it indicates these samples all have ~6 or 9 fits, I do not want any assumptions to be made. I'd like this to be flexible if the number of fits or parameters change.
At the end the of the day, I am trying to show via these plots the results for these 3 different methods of fitting. The code does work, and the output is the desired output (short of somehow connecting the pints with lines). Any assisstance in simplifying the code/cleaning it up would greatly be appreciated!
Here is the csv, it should be noted I'm not posting the whole thing cause it's quite big, but the code works just fine if you have the whole thing or only portions:
Sample,RedChi2,DoF,Variables,Solutions±Uncertanties
WT_2017
Closed_Single_Scale,11.651219458497874,1361,scaling_factor,5.289818805209734e-09±2.5333027184960425e-12
Open_Single_Scale,129.7644067034128,1361,scaling_factor,5.78352277180727e-09±9.267293505002799e-12
Monomer_Single_Scale,2800.8454801421376,1361,scaling_factor,1.237352353911092e-08±9.567271509437632e-11
Closed_Individual_Scales,3.141241032954263,1359,scaling_factor10_0,scaling_factor5_0,scaling_factor2_5,5.278888659532299e-09±2.0916648214625956e-12,2.6134330255445093e-09±1.0297600525607774e-12,1.361607049332747e-09±7.479465652276344e-13
Open_Individual_Scales,121.77990881704223,1359,scaling_factor10_0,scaling_factor5_0,scaling_factor2_5,5.768979516318495e-09±1.4261604970796457e-11,2.859028569446309e-09±6.999458673819623e-12,1.4881584853299046e-09±5.113383427746122e-12
Monomer_Individual_Scales,2753.526962174867,1359,scaling_factor10_0,scaling_factor5_0,scaling_factor2_5,1.1981053926746199e-08±1.466593144330762e-10,6.178167533121837e-09±7.458798290561859e-11,3.332717657400508e-09±5.611785789102205e-11
Closed,5.145880930141789,453,scaling_factor10_0,5.278888659532299e-09±2.6715171812012825e-12
Closed,2.608291185540206,453,scaling_factor5_0,2.6134330255445093e-09±9.343709358604779e-13 | {
"domain": "codereview.stackexchange",
"id": 44996,
"lm_label": null,
"lm_name": null,
"lm_q1_score": null,
"lm_q1q2_score": null,
"lm_q2_score": null,
"openwebmath_perplexity": null,
"openwebmath_score": null,
"tags": "python",
"url": null
} |
python
Closed,2.608291185540206,453,scaling_factor5_0,2.6134330255445093e-09±9.343709358604779e-13
Closed,1.6695509831807942,453,scaling_factor2_5,1.361607049332747e-09±5.497499488566032e-13
Open,167.8652258687902,453,scaling_factor10_0,5.768979516318495e-09±1.6744066557640155e-11
Open,132.19332948498598,453,scaling_factor5_0,2.859028569446309e-09±7.320959381300875e-12
Open,65.28117109719815,453,scaling_factor2_5,1.4881587073745095e-09±3.743815411988221e-12
Monomer,3684.2717626106696,453,scaling_factor10_0,1.1981053926746199e-08±1.6964724789096872e-10
Monomer,3191.617700825002,453,scaling_factor5_0,6.178167311077232e-09±8.044704750400721e-11
Monomer,1384.6914230889292,453,scaling_factor2_5,3.332717657400508e-09±3.979540271093099e-11
Open-Closed_Single_Scales,11.595816796203142,1360,k,scaling_factor,0.025468443075522762±0.00951400354085251,5.301449279571102e-09±4.9480963745005665e-12
Monomer-Open_Single_Scales,116.95904024312684,1360,k,scaling_factor,1353.0694130583356±227.22472864506145,1.1682963707571048e-08±1.9956768284411006e-11
Monomer-Closed_Single_Scales,11.701008294872302,1360,k,scaling_factor,4.967966038549321e-10±4.665887838579333e-05,1.0590763377393841e-08±6.879643312260799e-12
Open-Closed_Individual_Scales,3.0917879513608395,1358,k,scaling_factor10_0,scaling_factor5_0,scaling_factor2_5,0.02286091209854013±0.004894202420378687,5.289336746372442e-09±3.0206403372055097e-12,2.6186248724968664e-09±1.4977587234825428e-12,1.3642733609486868e-09±9.3129932098768e-13
Monomer-Open_Individual_Scales,104.99157760961575,1358,k,scaling_factor10_0,scaling_factor5_0,scaling_factor2_5,1824.593441807333±255.97176256453696,1.1619162743059519e-08±2.7164270673968367e-11,5.7877602710476594e-09±1.3947691690638419e-11,3.0351223756497347e-09±1.0399618523725143e-11 | {
"domain": "codereview.stackexchange",
"id": 44996,
"lm_label": null,
"lm_name": null,
"lm_q1_score": null,
"lm_q1q2_score": null,
"lm_q2_score": null,
"openwebmath_perplexity": null,
"openwebmath_score": null,
"tags": "python",
"url": null
} |
python
Monomer-Closed_Individual_Scales,3.149270506823421,1358,k,scaling_factor10_0,scaling_factor5_0,scaling_factor2_5,3.4835001549993194e-10±2.1481406531228426e-05,1.0560253560498722e-08±4.4991774377778e-12,5.228859123462826e-09±2.4358803824976767e-12,2.724843684021039e-09±1.8261869098218406e-12
Open-Closed,5.093758714709088,452,k,scaling_factor10_0,0.021601450949922274±0.009278757362582764,5.288772753075932e-09±4.945104972194297e-12
Monomer-Open,160.6094864099725,452,k,scaling_factor10_0,4379.220983433397±1884.292849140677,6.079450942664266e-09±6.905468982650861e-11
Monomer-Closed,5.167930502573018,452,k,scaling_factor10_0,1.987332520769769e-10±8.290787869327447e-05,5.28147703349191e-09±1.3759909246526632e-11
Open-Closed,2.3982970023387313,452,k,scaling_factor5_0,0.04461782513617307±0.0072813114201538,2.6233668570796453e-09±1.7928637305077058e-12
Monomer-Open,110.09824101051218,452,k,scaling_factor5_0,14532.470313102183±3017.2862128834013,3.1471107941882792e-09±3.083091173419714e-11
Monomer-Closed,2.614448761890241,452,k,scaling_factor5_0,6.949574249404122e-11±3.992641374800452e-05,2.6136754982530874e-09±5.368761290755311e-12
Open-Closed,1.6732446800491425,452,k,scaling_factor2_5,1.3371526108585385e-12±0,1.361607049332747e-09±0
Monomer-Open,44.048643057572214,452,k,scaling_factor2_5,31238.857552466867±4199.205126447735,1.7132935070662825e-09±1.5540806078947448e-11
Monomer-Closed,1.3539506956359522,452,k,scaling_factor2_5,673.5376422118167±129.95085585888123,1.3933125764253873e-09±3.0978097357861177e-12
3-state_Single_Scale,11.63431283275547,1359,k,k1,scaling_factor,9.754255181348981e-09±0.0010506793496375386,0.042094986833364656±0.010101060278893851,1.0621255874809776e-08±1.2008013701909137e-11
3-state_Individual_Scale,3.1458718903777783,1357,k,k1,scaling_factor10_0,scaling_factor5_0,scaling_factor2_5,266.6998426893263±0,8.482103908136196e-13±0,1.0557777319064598e-08±0,5.226865829044414e-09±0,2.723214098665494e-09±0 | {
"domain": "codereview.stackexchange",
"id": 44996,
"lm_label": null,
"lm_name": null,
"lm_q1_score": null,
"lm_q1q2_score": null,
"lm_q2_score": null,
"openwebmath_perplexity": null,
"openwebmath_score": null,
"tags": "python",
"url": null
} |
python
3-state,5.168700807063889,451,k,k1,scaling_factor10_0,0.004422182275551023±0,1.2589929099249275e-13±0,1.0557777319064598e-08±0
3-state,2.462562343123655,451,k,k1,scaling_factor5_0,1.409901331239638e-07±0.006012009829771037,0.021228946386903313±0.007359439924888416,5.237557720860764e-09±4.569643902687795e-12
3-state,1.3533760673426907,451,k,k1,scaling_factor2_5,20431.001449073894±17640.64419462182,0.009184004111323363±0.00848783561315988,2.7378384004350664e-09±2.85108716910804e-12
5-state_Single_Scale,11.676958529840041,1358,k,k1,k2,scaling_factor,4955.72717993047±0,4.099387496125928e-12±0,2.0909629583343303e-10±0,1.0579637610419468e-08±0
5-state_Individual_Scale,3.067767015491633,1356,k,k1,k2,scaling_factor10_0,scaling_factor5_0,scaling_factor2_5,170856.67831215993±0,0.0429057854001933±0,1.4699352846037073e-13±0,1.0582846599049844e-08±0,5.239242595322935e-09±0,2.72953482038929e-09±0
5-state,5.024034823707327,450,k,k1,k2,scaling_factor10_0,2084.0699773666047±0,0.05172348677301808±0,1.4654943925052066e-14±0,1.0587753118684873e-08±0
5-state,2.3813253147933615,450,k,k1,k2,scaling_factor5_0,32030.340564547354±0,0.07161846247884407±0,2.8845814625810817e-12±0,5.246990619767189e-09±0
5-state,1.3546985000448537,450,k,k1,k2,scaling_factor2_5,14102821.146870395±395677234022.2835,0.01820376302731841±0.6571544682360568,0.0007367715684281073±20.96431638894048,2.738050230988165e-09±3.5871709217682943e-12
L273A_2019
Closed_Single_Scale,9.174003184243801,2681,scaling_factor,4.324745228601046e-09±2.765306029560602e-12
Open_Single_Scale,39.8123724158422,2681,scaling_factor,4.721149471365038e-09±6.2965175662180825e-12
Monomer_Single_Scale,525.5605765481052,2681,scaling_factor,1.0463764743562365e-08±5.231733588745123e-11 | {
"domain": "codereview.stackexchange",
"id": 44996,
"lm_label": null,
"lm_name": null,
"lm_q1_score": null,
"lm_q1q2_score": null,
"lm_q2_score": null,
"openwebmath_perplexity": null,
"openwebmath_score": null,
"tags": "python",
"url": null
} |
python
Closed_Individual_Scales,2.2483901834385485,2676,scaling_factor0_9,scaling_factor0_225,scaling_factor2_2,scaling_factor0_45,scaling_factor8_8,scaling_factor4_499999999999999,4.952529497614933e-10±8.895519981225783e-13,1.0049072685092142e-10±7.024029589104452e-13,1.0189906696211892e-09±1.0785836859346905e-12,2.315752034576235e-10±8.66827219417161e-13,4.372231909854918e-09±1.8846203879984473e-12,2.1901891411602037e-09±1.2157238197957538e-12
Open_Individual_Scales,32.90813128302828,2676,scaling_factor0_9,scaling_factor0_225,scaling_factor2_2,scaling_factor0_45,scaling_factor8_8,scaling_factor4_499999999999999,5.387128521050499e-10±3.6215503085391533e-12,1.090205703491165e-10±2.85113842925099e-12,1.1106386921255762e-09±4.517671601553341e-12,2.5151081217700266e-10±3.5624930347816784e-12,4.7765111865771814e-09±7.861370196284916e-12,2.3903390378166023e-09±5.061596091690976e-12
Monomer_Individual_Scales,517.0751249647922,2676,scaling_factor0_9,scaling_factor0_225,scaling_factor2_2,scaling_factor0_45,scaling_factor8_8,scaling_factor4_499999999999999,1.2877119370813261e-09±3.528322691293619e-11,2.6786373119591644e-10±2.884185447299622e-11,2.5816544457768487e-09±4.2460341760827645e-11,6.113911599214816e-10±3.386652413815416e-11,1.0323902621678371e-08±6.979956274089994e-11,5.402667868636968e-09±4.679439198788712e-11
Closed,2.245122866419131,446,scaling_factor0_9,4.952531718060982e-10±8.691523910302594e-13
Closed,1.2220826927570207,446,scaling_factor0_225,1.0049072685092142e-10±5.178461943489442e-13
Closed,2.6172756333626133,446,scaling_factor2_2,1.0189906696211892e-09±1.1637046322059817e-12
Closed,1.6273562331130582,446,scaling_factor0_45,2.3157542550222843e-10±7.023434751397684e-13
Closed,2.042783765679194,446,scaling_factor8_8,4.372232131899523e-09±1.7918247479175208e-12
Closed,3.735719909464074,446,scaling_factor4_499999999999999,2.1901891411602037e-09±1.5670621772968183e-12
Open,7.343419330292259,446,scaling_factor0_9,5.387128521050499e-10±1.7107718584314595e-12 | {
"domain": "codereview.stackexchange",
"id": 44996,
"lm_label": null,
"lm_name": null,
"lm_q1_score": null,
"lm_q1q2_score": null,
"lm_q2_score": null,
"openwebmath_perplexity": null,
"openwebmath_score": null,
"tags": "python",
"url": null
} |
python
Open,7.343419330292259,446,scaling_factor0_9,5.387128521050499e-10±1.7107718584314595e-12
Open,1.5610346525856384,446,scaling_factor0_225,1.090205703491165e-10±6.209733542130735e-13
Open,18.101771751866902,446,scaling_factor2_2,1.1106386921255762e-09±3.3506079933593513e-12
Open,3.016757393900973,446,scaling_factor0_45,2.5151081217700266e-10±1.031740474882739e-12
Open,105.72059055509118,446,scaling_factor8_8,4.7765111865771814e-09±1.4123261647899516e-11
Open,61.70521401443275,446,scaling_factor4_499999999999999,2.3903390378166023e-09±6.931014610108402e-12
Monomer,64.45557658838904,446,scaling_factor0_9,1.2877119370813261e-09±1.2457236239895235e-11
Monomer,4.50544005790289,446,scaling_factor0_225,2.678641752851263e-10±2.6919738301248977e-12
Monomer,212.06496531273785,446,scaling_factor2_2,2.5816544457768487e-09±2.7309207785959558e-11
Monomer,14.17401674731078,446,scaling_factor0_45,6.113913819660866e-10±5.607117255876318e-12
Monomer,1890.3602574492807,446,scaling_factor8_8,1.0323902621678371e-08±1.3345907532822308e-10
Monomer,916.8904936328964,446,scaling_factor4_499999999999999,5.402668090681573e-09±6.218462909338317e-11
Open-Closed_Single_Scales,9.177426321803827,2680,k,scaling_factor,4.425571020760799e-11±0.005748260336874386,4.3247430081549965e-09±4.09022039840387e-12
Monomer-Open_Single_Scales,29.519618174489032,2680,k,scaling_factor,5200.38344226182±362.75141183609253,9.658067900986111e-09±1.2927555490155494e-11
Monomer-Closed_Single_Scales,8.417352983890101,2680,k,scaling_factor,404.642546715369±52.72808373756473,8.730888900743139e-09±7.435971608197247e-12
Open-Closed_Individual_Scales,2.249230703133292,2675,k,scaling_factor0_9,scaling_factor0_225,scaling_factor2_2,scaling_factor0_45,scaling_factor8_8,scaling_factor4_499999999999999,0.0±0,4.952529497614933e-10±0,1.0049072685092142e-10±0,1.0189906696211892e-09±0,2.315752034576235e-10±0,4.372231909854918e-09±0,2.1901891411602037e-09±0 | {
"domain": "codereview.stackexchange",
"id": 44996,
"lm_label": null,
"lm_name": null,
"lm_q1_score": null,
"lm_q1q2_score": null,
"lm_q2_score": null,
"openwebmath_perplexity": null,
"openwebmath_score": null,
"tags": "python",
"url": null
} |
python
Monomer-Open_Individual_Scales,22.02833912577891,2675,k,scaling_factor0_9,scaling_factor0_225,scaling_factor2_2,scaling_factor0_45,scaling_factor8_8,scaling_factor4_499999999999999,5839.181064464672±344.7897446709904,1.1485725703863636e-09±6.565575676164824e-12,2.4459523295661256e-10±5.361461811272807e-12,2.3123121195567364e-09±8.038381645968701e-12,5.492586385713594e-10±6.318351225421843e-12,9.707401771308355e-09±1.3731321867458155e-11,4.908826012339773e-09±9.16822947360435e-12
Monomer-Closed_Individual_Scales,1.3795895692374776,2675,k,scaling_factor0_9,scaling_factor0_225,scaling_factor2_2,scaling_factor0_45,scaling_factor8_8,scaling_factor4_499999999999999,585.9927902689327±29.125761246573827,1.0204164180294129e-09±1.581945857464346e-12,2.1329960020466388e-10±1.2077975435046012e-12,2.075653871003169e-09±1.9474686953061366e-12,4.832798605747257e-10±1.4213422350028869e-12,8.812909735311791e-09±3.4086897229438337e-12,4.433950762106065e-09±2.3245146604652868e-12
Open-Closed,2.2501680989281625,445,k,scaling_factor0_9,3.601563491884008e-13±0.00039339323169999173,4.952516174938637e-10±1.0907828247456708e-12
Monomer-Open,2.643498406838119,445,k,scaling_factor0_9,11564.106709199183±832.4210026743647,7.106226718178732e-10±6.189163102578837e-12
Monomer-Closed,1.2506878262845327,445,k,scaling_factor0_9,3567.1952189406447±371.7132629283984,5.881983788924572e-10±4.970131183993243e-12
Open-Closed,1.2248289459993624,445,k,scaling_factor0_225,1.5363266214762916e-12±0,1.0049072685092142e-10±0
Monomer-Open,1.1850961371308917,445,k,scaling_factor0_225,16474.79589624025±2833.255958239668,1.5117329610347952e-10±3.4762309140180773e-12
Monomer-Closed,1.1263909988040377,445,k,scaling_factor0_225,6247.748874292872±1969.2997559906846,1.2589906894788783e-10±4.231083127457938e-12
Open-Closed,2.623157151647579,445,k,scaling_factor2_2,1.8405277302235845e-12±0,1.0189906696211892e-09±0 | {
"domain": "codereview.stackexchange",
"id": 44996,
"lm_label": null,
"lm_name": null,
"lm_q1_score": null,
"lm_q1q2_score": null,
"lm_q2_score": null,
"openwebmath_perplexity": null,
"openwebmath_score": null,
"tags": "python",
"url": null
} |
python
Monomer-Open,7.770735947033868,445,k,scaling_factor2_2,7988.70846864133±659.7494719524013,1.4004151172031243e-09±1.2104270169780753e-11
Monomer-Closed,1.0355285991781933,445,k,scaling_factor2_2,1768.6165511868628±133.37423027538938,1.151150952338753e-09±5.097243955583818e-12
Open-Closed,1.6310132144695257,445,k,scaling_factor0_45,6.110232320111209e-10±0.0405197656696667,2.3157564754683335e-10±1.5422258273095806e-12
Monomer-Open,1.4451484300339723,445,k,scaling_factor0_45,17268.28261839559±1616.3344267222324,3.5018987709634075e-10±4.613703295574204e-12
Monomer-Closed,1.1788814567239638,445,k,scaling_factor0_45,7141.302548479925±1077.4530781042545,2.938829180010316e-10±4.8942396558448616e-12
Open-Closed,2.0473742914774045,445,k,scaling_factor8_8,8.531841899639403e-12±0.0006707084729411748,4.372231465765708e-09±2.3522225211330147e-12
Monomer-Open,83.20355792437526,445,k,scaling_factor8_8,2152.549420623712±389.0190619421427,5.394261037849901e-09±5.7365519987939135e-11
Monomer-Closed,1.6443282853402037,445,k,scaling_factor8_8,52.78014094104868±10.072797205777396,4.465588565594203e-09±9.087472033649693e-12
Open-Closed,3.7441148123805843,445,k,scaling_factor4_499999999999999,2.2196633420179523e-09±0.04112432744661495,2.1901891411602037e-09±2.3820062056514955e-12
Monomer-Open,35.19038659312791,445,k,scaling_factor4_499999999999999,4965.370825746898±541.0809480169584,2.873749238574419e-09±2.6937582360362584e-11
Monomer-Closed,1.2707751195070658,445,k,scaling_factor4_499999999999999,657.6201874635033±44.20909138976637,2.3601220977553794e-09±5.834364711089205e-12
3-state_Single_Scale,8.420501324075516,2679,k,k1,scaling_factor,173323692.0148578±961191964643.7219,2.334323252695114e-06±0.013176934295718477,8.730889788921559e-09±1.357784081349648e-11 | {
"domain": "codereview.stackexchange",
"id": 44996,
"lm_label": null,
"lm_name": null,
"lm_q1_score": null,
"lm_q1q2_score": null,
"lm_q2_score": null,
"openwebmath_perplexity": null,
"openwebmath_score": null,
"tags": "python",
"url": null
} |
python
3-state_Individual_Scale,1.3801074164211111,2674,k,k1,scaling_factor0_9,scaling_factor0_225,scaling_factor2_2,scaling_factor0_45,scaling_factor8_8,scaling_factor4_499999999999999,720058911.4182954±4712417688820.822,8.137853728662492e-07±0.0053788564602851065,1.0204164180294129e-09±1.7394690811836413e-12,2.1329960020466388e-10±1.1661035918187955e-12,2.075654093047774e-09±2.2827810147278105e-12,4.832798605747257e-10±1.5053607166426584e-12,8.812910401445606e-09±5.6680774433197645e-12,4.433951206195275e-09±3.3250908468501782e-12
3-state,1.244004320287907,444,k,k1,scaling_factor0_9,15288.660354275029±7600.133501130614,0.08010109109537744±0.04703313260315362,1.0371219438809476e-09±4.809874174179948e-12
3-state,1.1275742507853492,444,k,k1,scaling_factor0_225,17070.73901207036±20729.292444531613,0.14418973696021986±0.2268113945120016,2.14685380584001e-10±4.231090299795642e-12
3-state,1.0378627351976344,444,k,k1,scaling_factor2_2,185305492.37827435±1353034804097.2397,2.6271656914378383e-06±0.019327436405283997,2.091002038184797e-09±4.815904227794891e-12
3-state,1.179350664883329,444,k,k1,scaling_factor0_45,29028.655566232967±29749.387769850753,0.08716474531020513±0.10464625355338188,4.935911679382343e-10±4.841338936627694e-12
3-state,1.6480334379433648,444,k,k1,scaling_factor8_8,74927496.51422621±3011333184521.274,1.7918114592063716e-07±0.00730035019924905,8.777190974029736e-09±7.790465219769675e-12
3-state,1.2736395883507758,444,k,k1,scaling_factor4_499999999999999,341002705.1497503±6514805360824.465,5.119172821199669e-07±0.00985172798822378,4.445436907474232e-09±5.293286935875841e-12
5-state_Single_Scale,8.40955598492184,2678,k,k1,k2,scaling_factor,894183.820234663±0,0.0019627685263932104±0,0.22895838959938652±0,8.729908573812395e-09±0 | {
"domain": "codereview.stackexchange",
"id": 44996,
"lm_label": null,
"lm_name": null,
"lm_q1_score": null,
"lm_q1q2_score": null,
"lm_q2_score": null,
"openwebmath_perplexity": null,
"openwebmath_score": null,
"tags": "python",
"url": null
} |
python
5-state_Individual_Scale,1.3750978968802392,2673,k,k1,k2,scaling_factor0_9,scaling_factor0_225,scaling_factor2_2,scaling_factor0_45,scaling_factor8_8,scaling_factor4_499999999999999,649498.1408342685±0,0.0020835053600749553±0,0.42176400635655975±0,1.0197191979699483e-09±0,2.1299517705131166e-10±0,2.074852067934785e-09±0,4.827949151575694e-10±0,8.81201112079566e-09±0,4.432983313762406e-09±0
5-state,1.2452518892390327,443,k,k1,k2,scaling_factor0_9,3649982.504501755±22306878898.512386,0.15932930054151084±4.054209756390413,0.002229116300540568±13.79015616166845,1.037005148418757e-09±6.034920916159181e-12
5-state,1.130119108040711,443,k,k1,k2,scaling_factor0_225,17092.829716577817±265466.3034728167,0.0004203233055524169±5.287435769419636,342.6489022771118±4348532.821278521,2.14685380584001e-10±4.0344409763510615e-12
5-state,1.0351970023783603,443,k,k1,k2,scaling_factor2_2,362436.84824600193±0,0.004181198773479666±0,0.3123394966250155±0,2.0898163199944975e-09±0
5-state,1.1811357756947156,443,k,k1,k2,scaling_factor0_45,6116591.489852166±55598825090.851326,0.19189087642436364±7.956031680077219,0.0023220990971331013±21.420629267453638,4.935591935151251e-10±5.475331873083644e-12
5-state,1.6382482016899793,443,k,k1,k2,scaling_factor8_8,117713.53150950116±0,0.0005066456475271153±0,0.22276226802308963±0,8.776464222037816e-09±0
5-state,1.2791134807665492,443,k,k1,k2,scaling_factor4_499999999999999,59978.21805902952±0,0.0032382304805331774±0,0.8826073812364774±0,4.4455352732342135e-09±0
I272A_2017
Closed_Single_Scale,10.077660131820537,1361,scaling_factor,1.5195864566663886e-09±1.4041288083816979e-12
Open_Single_Scale,40.00873007882292,1361,scaling_factor,1.6588812545847986e-09±3.05046659535348e-12
Monomer_Single_Scale,434.75589360377063,1361,scaling_factor,3.774386136967678e-09±2.3510228611977692e-11 | {
"domain": "codereview.stackexchange",
"id": 44996,
"lm_label": null,
"lm_name": null,
"lm_q1_score": null,
"lm_q1q2_score": null,
"lm_q2_score": null,
"openwebmath_perplexity": null,
"openwebmath_score": null,
"tags": "python",
"url": null
} |
python
Closed_Individual_Scales,6.205076198847537,1359,scaling_factor3_7,scaling_factor1_85,scaling_factor0_925,1.5415724252676455e-09±1.354111582753058e-12,7.439477922588367e-10±1.1569210511406288e-12,3.633233713884465e-10±8.210477930916591e-13
Open_Individual_Scales,35.75040735204575,1359,scaling_factor3_7,scaling_factor1_85,scaling_factor0_925,1.6841836814052158e-09±3.5536331430248995e-12,8.115614846815333e-10±3.038296413289823e-12,3.9547121133409746e-10±2.144362879347458e-12
Monomer_Individual_Scales,435.34291271350827,1359,scaling_factor3_7,scaling_factor1_85,scaling_factor0_925,3.78058584438179e-09±2.8580304706464382e-11,1.8787320588131706e-09±2.505168813012816e-11,9.425089597669967e-10±1.829913208901307e-11
Closed,8.698090383957643,453,scaling_factor3_7,1.5415726473122504e-09±1.603219285316849e-12
Closed,5.790954207560294,453,scaling_factor1_85,7.439477922588367e-10±1.1176484297450035e-12
Closed,4.126184005193661,453,scaling_factor0_925,3.633233713884465e-10±6.695286629579998e-13
Open,68.0526173088621,453,scaling_factor3_7,1.6841836814052158e-09±4.902916655781307e-12
Open,25.312650389033205,453,scaling_factor1_85,8.115614846815333e-10±2.5565744449155122e-12
Open,13.88595435739187,453,scaling_factor0_925,3.954707672448876e-10±1.374596439573057e-12
Monomer,954.9159242043648,453,scaling_factor3_7,3.78058584438179e-09±4.232857842107978e-11
Monomer,252.25939340758032,453,scaling_factor1_85,1.8787318367685657e-09±1.9069806541342135e-11
Monomer,98.85342052853116,453,scaling_factor0_925,9.425087377223917e-10±8.71988387545325e-12
Open-Closed_Single_Scales,10.085070177091046,1360,k,scaling_factor,5.278888437487694e-12±0.0015018338723078069,1.5195857905325738e-09±2.609848716517211e-12
Monomer-Open_Single_Scales,15.332529600935272,1360,k,scaling_factor,7364.423376672264±353.32129467610883,3.4487934730265124e-09±4.7249311070061075e-12 | {
"domain": "codereview.stackexchange",
"id": 44996,
"lm_label": null,
"lm_name": null,
"lm_q1_score": null,
"lm_q1q2_score": null,
"lm_q2_score": null,
"openwebmath_perplexity": null,
"openwebmath_score": null,
"tags": "python",
"url": null
} |
python
Monomer-Closed_Single_Scales,2.770769832627186,1360,k,scaling_factor,2582.089226893949±92.63133954810608,3.1415443579874136e-09±2.2855346095340507e-12
Open-Closed_Individual_Scales,6.2096454744267175,1358,k,scaling_factor3_7,scaling_factor1_85,scaling_factor0_925,4.240607864858248e-12±0,1.5415724252676455e-09±0,7.439477922588367e-10±0,3.633233713884465e-10±0
Monomer-Open_Individual_Scales,14.362605937067253,1358,k,scaling_factor3_7,scaling_factor1_85,scaling_factor0_925,6807.878908487171±332.747203564248,3.470593368248842e-09±5.118919382786397e-12,1.6983012773863493e-09±4.3030861189176095e-12,8.451896960082195e-10±3.123558106773469e-12
Monomer-Closed_Individual_Scales,1.5253344981989596,1358,k,scaling_factor3_7,scaling_factor1_85,scaling_factor0_925,1918.0085797475097±61.805241613490395,3.155615102556908e-09±1.7709394003006822e-12,1.5402359387906017e-09±1.4238886832700564e-12,7.642986243894256e-10±1.026105554503271e-12
Open-Closed,8.717333946755954,452,k,scaling_factor3_7,1.8962609260597674e-13±0,1.5415726473122504e-09±0
Monomer-Open,30.712544397434982,452,k,scaling_factor3_7,25852.85284743095±2213.615347882836,2.0649715271048308e-09±1.6543211734490386e-11
Monomer-Closed,1.7779614830960988,452,k,scaling_factor3_7,6694.153917938665±314.60472574338945,1.7300347820992101e-09±4.569567752495378e-12
Open-Closed,5.803766068026525,452,k,scaling_factor1_85,2.6402073860509745e-09±0.054158630946557436,7.439475702142317e-10±1.4420899335441793e-12
Monomer-Open,7.9971058805539155,452,k,scaling_factor1_85,42839.238183414935±2777.701984562573,1.0519243254236699e-09±7.783331649041986e-12
Monomer-Closed,1.4076677871757326,452,k,scaling_factor1_85,15312.824926173398±803.0930128497289,8.843676901904018e-10±3.761639122250833e-12
Open-Closed,4.135312735579967,452,k,scaling_factor0_925,8.866558598441543e-10±0.0437872089309321,3.633231493438416e-10±1.4794490013075043e-12 | {
"domain": "codereview.stackexchange",
"id": 44996,
"lm_label": null,
"lm_name": null,
"lm_q1_score": null,
"lm_q1q2_score": null,
"lm_q2_score": null,
"openwebmath_perplexity": null,
"openwebmath_score": null,
"tags": "python",
"url": null
} |
python
Monomer-Open,4.068441749943383,452,k,scaling_factor0_925,60226.243340074994±3737.2749036249234,5.366267430417793e-10±4.3598019365402184e-12
Monomer-Closed,1.3732911641653351,452,k,scaling_factor0_925,24074.245724112978±1573.5943835975943,4.508386997059688e-10±2.9730957346274003e-12
3-state_Single_Scale,2.758204825138075,1359,k,k1,scaling_factor,80003.409589152±29195.773371130672,0.03443900107000086±0.013420560720835539,3.151198635364949e-09±4.347378021831141e-12
3-state_Individual_Scale,1.5195031977347064,1357,k,k1,scaling_factor3_7,scaling_factor1_85,scaling_factor0_925,86375.563168806±33735.533865868194,0.023397337180762534±0.009601255285663668,3.162473838358437e-09±3.2682727363070853e-12,1.5436776301669397e-09±1.9839850031906996e-12,7.660685419352831e-10±1.248294970220343e-12
3-state,1.7627737844684976,451,k,k1,scaling_factor3_7,75605.01393759178±33103.9550997459,0.025835872812350225±0.011973317581912096,3.161811035212736e-09±4.121165814211037e-12
3-state,1.4011515554201008,451,k,k1,scaling_factor1_85,125199.05670955798±68493.83066998914,0.037880514495948425±0.022317161492702298,1.5490277949226083e-09±3.5892195783564337e-12
3-state,1.376339049569443,451,k,k1,scaling_factor0_925,556467334.9386779±1479253248310.896,1.2781384682636343e-05±0.034247612465275995,7.63006324788762e-10±2.8730481053742913e-12
5-state_Single_Scale,2.760241519396153,1358,k,k1,k2,scaling_factor,79997.27739009078±30667.728587657944,3.2574836339449575e-06±0.0395382186497476,10572.995395572681±127357363.72607899,3.1511997455879737e-09±4.349646905192765e-12
5-state_Individual_Scale,1.512548169906363,1356,k,k1,k2,scaling_factor3_7,scaling_factor1_85,scaling_factor0_925,75504542.48167497±258872581610.6548,0.05845505625540781±0.18256000008961404,0.00046220158460696936±1.5963529789341953,3.1627418461965817e-09±3.364949727235645e-12,1.543197125641882e-09±2.066022335804619e-12,7.654430422832093e-10±1.4782639706737382e-12 | {
"domain": "codereview.stackexchange",
"id": 44996,
"lm_label": null,
"lm_name": null,
"lm_q1_score": null,
"lm_q1q2_score": null,
"lm_q2_score": null,
"openwebmath_perplexity": null,
"openwebmath_score": null,
"tags": "python",
"url": null
} |
python
5-state,1.7545524207000542,450,k,k1,k2,scaling_factor3_7,95675598.67151138±1435236884415.1064,0.05950243138544531±0.5931092155711732,0.0003479573904734412±5.258418128428876,3.161890971270509e-09±4.484085953236711e-12
5-state,1.3960133942921886,450,k,k1,k2,scaling_factor1_85,121696584.23342068±1738261883597.6584,0.08961514107127±1.1243637715005599,0.00044708519759395493±6.434842939634424,1.548922323735269e-09±3.8384952228258175e-12
5-state,1.3759560580385806,450,k,k1,k2,scaling_factor0_925,4757907.59863114±0,0.006559536761526097±0,0.22021109409960915±0,7.619289643656657e-10±0
ILAA_2017
Closed_Single_Scale,413.365367159509,1361,scaling_factor,2.511102659141784e-09±9.37501136995027e-12
Open_Single_Scale,546.2316866117975,1361,scaling_factor,2.7363595833662657e-09±1.1744865931293373e-11
Monomer_Single_Scale,379.73312828053326,1361,scaling_factor,6.3686522722150585e-09±2.2739050262010336e-11
Closed_Individual_Scales,372.73701811124585,1359,scaling_factor1_56,scaling_factor6_219999999999999,scaling_factor3_1099999999999994,5.696492166862299e-10±6.359442243684636e-12,2.5942019643565573e-09±1.1929184724334598e-11,1.2293064344248705e-09±7.961492987260457e-12
Open_Individual_Scales,502.8028440696418,1359,scaling_factor1_56,scaling_factor6_219999999999999,scaling_factor3_1099999999999994,6.185645329281897e-10±7.966659600677477e-12,2.830861989266964e-09±1.5112255716946714e-11,1.338208432954957e-09±1.0079494040075451e-11
Monomer_Individual_Scales,371.80164764919107,1359,scaling_factor1_56,scaling_factor6_219999999999999,scaling_factor3_1099999999999994,1.5150871668367927e-09±1.6642211349913526e-11,6.443148681256616e-09±2.966552533010347e-11,3.1762390495515547e-09±2.0310652540672856e-11
Closed,195.30007265331076,453,scaling_factor1_56,5.696492166862299e-10±4.603296687782962e-12
Closed,504.09711035058274,453,scaling_factor6_219999999999999,2.5942019643565573e-09±1.3872879193529421e-11 | {
"domain": "codereview.stackexchange",
"id": 44996,
"lm_label": null,
"lm_name": null,
"lm_q1_score": null,
"lm_q1q2_score": null,
"lm_q2_score": null,
"openwebmath_perplexity": null,
"openwebmath_score": null,
"tags": "python",
"url": null
} |
python
Closed,418.81387132984395,453,scaling_factor3_1099999999999994,1.2293064344248705e-09±8.439248637556243e-12
Open,254.15758815120364,453,scaling_factor1_56,6.185645329281897e-10±5.7670685400903835e-12
Open,697.8819957681799,453,scaling_factor6_219999999999999,2.830861989266964e-09±1.7804157526099528e-11
Open,556.3689482895419,453,scaling_factor3_1099999999999994,1.338208432954957e-09±1.060282054886333e-11
Monomer,28.453888620248343,453,scaling_factor1_56,1.5150871668367927e-09±4.570303595300972e-12
Monomer,875.875790594124,453,scaling_factor6_219999999999999,6.443148681256616e-09±4.5453730360383616e-11
Monomer,211.0752637332007,453,scaling_factor3_1099999999999994,3.1762390495515547e-09±1.5303365184983175e-11
Open-Closed_Single_Scales,413.66931388082867,1360,k,scaling_factor,8.64026694635811e-09±0.07828023650710832,2.5110855617072048e-09±1.9301886793018273e-11
Monomer-Open_Single_Scales,14.063722494940981,1360,k,scaling_factor,169147.65732895603±2453.981487095853,6.08982109184808e-09±4.668396736199165e-12
Monomer-Closed_Single_Scales,11.531513242724202,1360,k,scaling_factor,153935.156179966±2203.6231577906715,5.814759340694309e-09±4.884042811366343e-12
Open-Closed_Individual_Scales,373.01149514010433,1358,k,scaling_factor1_56,scaling_factor6_219999999999999,scaling_factor3_1099999999999994,5.314304551973237e-11±0.014900127755724666,5.696332294746753e-10±7.386874720610564e-12,2.5941915282601258e-09±2.0488947117371618e-11,1.229301993532772e-09±1.1090279922207277e-11
Monomer-Open_Individual_Scales,6.127469962898049,1358,k,scaling_factor1_56,scaling_factor6_219999999999999,scaling_factor3_1099999999999994,166485.66145432417±1594.998294598453,1.4537127057678845e-09±2.0721858182615297e-12,6.162623078509455e-09±3.836027730640679e-12,3.0267588435606285e-09±2.587510313657167e-12 | {
"domain": "codereview.stackexchange",
"id": 44996,
"lm_label": null,
"lm_name": null,
"lm_q1_score": null,
"lm_q1q2_score": null,
"lm_q2_score": null,
"openwebmath_perplexity": null,
"openwebmath_score": null,
"tags": "python",
"url": null
} |
python
Monomer-Closed_Individual_Scales,8.329272597386584,1358,k,scaling_factor1_56,scaling_factor6_219999999999999,scaling_factor3_1099999999999994,152057.3234292164±1854.9553655374427,1.409792949047528e-09±2.4204325368093667e-12,5.8505806865838395e-09±4.798741546675545e-12,2.903264295639474e-09±3.1661692285616107e-12
Open-Closed,195.73215296067542,452,k,scaling_factor1_56,7.860379014346108e-14±0,5.696541016675383e-10±0
Monomer-Open,1.5996812858413396,452,k,scaling_factor1_56,483266.54738067655±8175.153007388655,1.3076231208941635e-09±2.6109739796514486e-12
Monomer-Closed,2.316630375782253,452,k,scaling_factor1_56,465084.0006738645±9940.481688109401,1.2716467878703952e-09±3.665146133119412e-12
Open-Closed,505.2123700263776,452,k,scaling_factor6_219999999999999,7.807005486526464e-09±0.10755018754227313,2.594200187999718e-09±2.8278773814319254e-11
Monomer-Open,11.63197880962284,452,k,scaling_factor6_219999999999999,101217.73241293729±1541.6842786665886,4.6249510887719225e-09±1.120102669973198e-11
Monomer-Closed,13.53739470616842,452,k,scaling_factor6_219999999999999,91312.8025123724±1670.066607874417,4.324610669570461e-09±1.3677713812852235e-11
Open-Closed,419.74045075410146,452,k,scaling_factor3_1099999999999994,1.4811663007208153e-10±0.030424702786803738,1.2293044360234262e-09±8.632390532884259e-12
Monomer-Open,3.0474036374530957,452,k,scaling_factor3_1099999999999994,226141.33638437855±2482.2439192918796,2.5159978545019612e-09±4.173356668488878e-12
Monomer-Closed,6.446779802883306,452,k,scaling_factor3_1099999999999994,212745.55776148697±3647.9022482045993,2.4035622381290978e-09±6.992122999158364e-12
3-state_Single_Scale,9.31976905963604,1359,k,k1,scaling_factor,382280.7857882451±20826.590483826338,0.6947547331108437±0.0651931914380085,5.923480372871381e-09±7.541928570611091e-12 | {
"domain": "codereview.stackexchange",
"id": 44996,
"lm_label": null,
"lm_name": null,
"lm_q1_score": null,
"lm_q1q2_score": null,
"lm_q2_score": null,
"openwebmath_perplexity": null,
"openwebmath_score": null,
"tags": "python",
"url": null
} |
python
3-state_Individual_Scale,4.029526074139432,1357,k,k1,scaling_factor1_56,scaling_factor6_219999999999999,scaling_factor3_1099999999999994,265341.0516791888±6790.140323333308,1.4494795264142066±0.09229114545437311,1.4349781363165448e-09±1.8199334403187507e-12,6.0308937843700505e-09±5.841357911570501e-12,2.9743281171334957e-09±2.8823733944536695e-12
3-state,1.6032176083254301,451,k,k1,scaling_factor1_56,216663.6195481865±14741.768512738101,255.79928681145378±4692.002975932847,1.4634033984606276e-09±2.9023055514915244e-12
3-state,4.792954847138981,451,k,k1,scaling_factor6_219999999999999,65616.10477056878±2238.349103525658,1.1477947111748206±0.08472543152083521,5.993351370747746e-09±7.1055041015972715e-12
3-state,2.7143525019701307,451,k,k1,scaling_factor3_1099999999999994,118709.43158145348±4592.339504932961,3.31292890960723±0.5721337307671849,3.0082885071891496e-09±4.155940751271917e-12
5-state_Single_Scale,9.326660398134534,1358,k,k1,k2,scaling_factor,382279.7061700346±40655.779095538426,2.9277100265456824e-05±0.19255413488624357,23730.53652295257±154869048.72051847,5.923481483094406e-09±7.837664166022527e-12
5-state_Individual_Scale,3.7683250912164477,1356,k,k1,k2,scaling_factor1_56,scaling_factor6_219999999999999,scaling_factor3_1099999999999994,1789230.2623942145±4704611.148633674,3879165.520397084±1547231215139.085,0.09382057913730613±0.28673729902064765,1.4294463390740475e-09±2.0434269627004335e-12,6.030169030779575e-09±6.11555951502442e-12,2.9680886637351023e-09±2.8829369173710696e-12
5-state,1.6018106095574396,450,k,k1,k2,scaling_factor1_56,240871.32039217575±66175.94072505912,454906.4948943052±592470352670.5321,7.549634419397906±58.79168729820819,1.460481957593629e-09±2.9006428631213654e-12
5-state,4.51620246523451,450,k,k1,k2,scaling_factor6_219999999999999,361968243.0682681±2870456459218.411,28.000500171865923±464.58678678608857,9.938924323216192e-05±0.7911016902862975,5.9959679443721825e-09±8.617050573587395e-12 | {
"domain": "codereview.stackexchange",
"id": 44996,
"lm_label": null,
"lm_name": null,
"lm_q1_score": null,
"lm_q1q2_score": null,
"lm_q2_score": null,
"openwebmath_perplexity": null,
"openwebmath_score": null,
"tags": "python",
"url": null
} |
python
5-state,2.6067750542073242,450,k,k1,k2,scaling_factor3_1099999999999994,177364.82195604665±176543.5432466682,1992294.828737867±2200052820063.3037,1.0141765288124804±3.0702401400102404,3.0046363175273427e-09±4.179695783971539e-12
ILAA_2019
Closed_Single_Scale,171.43524221632472,2681,scaling_factor,7.944489732736315e-09±2.6206795205317744e-11
Open_Single_Scale,201.9073787542138,2681,scaling_factor,8.657383032684152e-09±3.112347523587737e-11
Monomer_Single_Scale,239.07260260069563,2681,scaling_factor,1.974756047573578e-08±7.740666473000952e-11
Closed_Individual_Scales,58.1109460769522,2676,scaling_factor19_5,scaling_factor1_3999999999999997,scaling_factor0_8000000000000002,scaling_factor9_6,scaling_factor5_2,scaling_factor2_9,9.333905870434478e-09±3.3186705429320795e-11,3.962532524326434e-10±4.7769598956620215e-12,1.8520518452191936e-10±4.170721941300807e-12,4.055243252309992e-09±1.1694938293073873e-11,2.013820221691276e-09±9.02650749518981e-12,9.785530163952672e-10±7.214180457945083e-12
Open_Individual_Scales,86.56553097240106,2676,scaling_factor19_5,scaling_factor1_3999999999999997,scaling_factor0_8000000000000002,scaling_factor9_6,scaling_factor5_2,scaling_factor2_9,1.0183576870659294e-08±4.429294484946535e-11,4.2974934721939917e-10±6.357311416453784e-12,2.0062396188791354e-10±5.666162093875748e-12,4.424262511903976e-09±1.5577148267036463e-11,2.193627501867468e-09±1.2113148330846049e-11,1.0637992708950605e-09±9.573796025295761e-12
Monomer_Individual_Scales,179.39626109848993,2676,scaling_factor19_5,scaling_factor1_3999999999999997,scaling_factor0_8000000000000002,scaling_factor9_6,scaling_factor5_2,scaling_factor2_9,2.1928057813980217e-08±1.396780950841162e-10,1.061926102607913e-09±2.2699098742550426e-11,5.010289960694081e-10±2.0141621536074742e-11,9.965094083241866e-09±5.104395140132695e-11,5.1143493884353575e-09±4.049276599050625e-11,2.5601689657150928e-09±3.308061148413248e-11 | {
"domain": "codereview.stackexchange",
"id": 44996,
"lm_label": null,
"lm_name": null,
"lm_q1_score": null,
"lm_q1q2_score": null,
"lm_q2_score": null,
"openwebmath_perplexity": null,
"openwebmath_score": null,
"tags": "python",
"url": null
} |
python
Closed,60.1429298822872,446,scaling_factor19_5,9.333905870434478e-09±3.3761945786265526e-11
Closed,18.41761436878413,446,scaling_factor1_3999999999999997,3.962532524326434e-10±2.6893025316053548e-12
Closed,5.94808950985908,446,scaling_factor0_8000000000000002,1.8520518452191936e-10±1.3343799832104065e-12
Closed,133.55082588278216,446,scaling_factor9_6,4.055243474354597e-09±1.7729321215576863e-11
Closed,86.67418372091689,446,scaling_factor5_2,2.013820221691276e-09±1.1084825077664906e-11
Closed,43.93203309704972,446,scaling_factor2_9,9.785530163952672e-10±6.272614577496507e-12
Open,94.5391123082182,446,scaling_factor19_5,1.018357664861469e-08±4.628794098837795e-11
Open,25.917739041851487,446,scaling_factor1_3999999999999997,4.2974912517479424e-10±3.4785850723493417e-12
Open,8.096454881018708,446,scaling_factor0_8000000000000002,2.0062396188791354e-10±1.732865038973967e-12
Open,204.09570057914647,446,scaling_factor9_6,4.424262289859371e-09±2.3978516066230623e-11
Open,125.24836772290216,446,scaling_factor5_2,2.193627501867468e-09±1.4570486645009186e-11
Open,61.49581130118388,446,scaling_factor2_9,1.0637992708950605e-09±8.069278531635456e-12
Monomer,445.6395397970904,446,scaling_factor19_5,2.1928057813980217e-08±2.2003574912692326e-10
Monomer,7.217665542792391,446,scaling_factor1_3999999999999997,1.061926102607913e-09±4.553033631823255e-12
Monomer,2.9932690562728137,446,scaling_factor0_8000000000000002,5.01029218114013e-10±2.601586067856279e-12
Monomer,472.16323396132486,446,scaling_factor9_6,9.965094083241866e-09±8.271772235066225e-11
Monomer,121.25241283944143,446,scaling_factor5_2,5.1143493884353575e-09±3.329005338063746e-11
Monomer,27.111445393948337,446,scaling_factor2_9,2.5601689657150928e-09±1.2804421761187277e-11
Open-Closed_Single_Scales,171.49921059029452,2680,k,scaling_factor,7.37410132956029e-13±0,7.944489732736315e-09±0 | {
"domain": "codereview.stackexchange",
"id": 44996,
"lm_label": null,
"lm_name": null,
"lm_q1_score": null,
"lm_q1q2_score": null,
"lm_q2_score": null,
"openwebmath_perplexity": null,
"openwebmath_score": null,
"tags": "python",
"url": null
} |
python
Monomer-Open_Single_Scales,70.92874282760769,2680,k,scaling_factor,180648.1939556157±8552.05898826828,1.893234857774928e-08±4.4342746185323245e-11
Monomer-Closed_Single_Scales,57.59427551278405,2680,k,scaling_factor,167130.13294088282±7820.728695601132,1.7981047983894882e-08±4.530127802576589e-11
Open-Closed_Individual_Scales,58.13266996561691,2675,k,scaling_factor19_5,scaling_factor1_3999999999999997,scaling_factor0_8000000000000002,scaling_factor9_6,scaling_factor5_2,scaling_factor2_9,2.6910673689428677e-09±0.02332746430449143,9.333905426345268e-09±4.4661001877582285e-11,3.962523642542237e-10±4.926248022381221e-12,1.851940822916731e-10±4.469963204655869e-12,4.055243252309992e-09±1.7566384614757113e-11,2.013820221691276e-09±1.1043074059509836e-11,9.78553238439872e-10±7.835411575322136e-12
Monomer-Open_Individual_Scales,5.167241294432489,2675,k,scaling_factor19_5,scaling_factor1_3999999999999997,scaling_factor0_8000000000000002,scaling_factor9_6,scaling_factor5_2,scaling_factor2_9,146210.65237071717±1946.0275675661787,2.1239876302203697e-08±2.2819854866668346e-11,1.014942352384196e-09±3.643718777089361e-12,4.846407719583112e-10±3.342145780165835e-12,9.474433904088642e-09±8.531817863049148e-12,4.832410915867058e-09±6.658299570270067e-12,2.4196100678608445e-09±5.350196177235857e-12
Monomer-Closed_Individual_Scales,3.1423074487631166,2675,k,scaling_factor19_5,scaling_factor1_3999999999999997,scaling_factor0_8000000000000002,scaling_factor9_6,scaling_factor5_2,scaling_factor2_9,122244.89573115774±1451.7721707666667,1.98512566385034e-08±1.7303007601502963e-11,9.79918812760161e-10±2.7738389074204745e-12,4.721552038233767e-10±2.5398353207456974e-12,8.902542703026484e-09±6.909924100905726e-12,4.573802669938232e-09±5.2394138895682335e-12,2.309037849812512e-09±4.116042771786476e-12
Open-Closed,60.05710215140675,445,k,scaling_factor19_5,0.08721880132047422±0.07358376564438329,9.39932642829433e-09±6.13051018950538e-11 | {
"domain": "codereview.stackexchange",
"id": 44996,
"lm_label": null,
"lm_name": null,
"lm_q1_score": null,
"lm_q1q2_score": null,
"lm_q2_score": null,
"openwebmath_perplexity": null,
"openwebmath_score": null,
"tags": "python",
"url": null
} |
python
Monomer-Open,13.769194097772626,445,k,scaling_factor19_5,428190.48892485764±17980.380809116265,1.4027888850520753e-08±7.716258433442939e-11
Monomer-Closed,6.1888233714582395,445,k,scaling_factor19_5,355513.7962068967±11794.93934147716,1.2841181007416935e-08±5.725482418642659e-11
Open-Closed,18.459002307672613,445,k,scaling_factor1_3999999999999997,2.650051511565721e-09±0.45584953550550084,3.9625103198659417e-10±6.101900286943461e-12
Monomer-Open,1.2434227274312937,445,k,scaling_factor1_3999999999999997,3840199.1671306365±143510.88801832078,8.636531489969457e-10±4.723471762436793e-12
Monomer-Closed,1.1859659611833797,445,k,scaling_factor1_3999999999999997,3419276.3905385095±134252.33704667923,8.228342451843673e-10±5.3515259835569775e-12
Open-Closed,5.961456005204406,445,k,scaling_factor0_8000000000000002,6.189433410241918e-10±0.14092657038058723,1.8520474043270951e-10±1.3642378736003652e-12
Monomer-Open,1.4357390814721263,445,k,scaling_factor0_8000000000000002,3966128.6611269894±309060.6666414353,4.076163850896819e-10±4.571641988095767e-12
Monomer-Closed,1.397496562992147,445,k,scaling_factor0_8000000000000002,3453327.9421765576±285873.2390727862,3.872333564913788e-10±5.321869386367792e-12
Open-Closed,133.8509401994476,445,k,scaling_factor9_6,1.0473488742945847e-10±0.021133059163298155,4.055233260302771e-09±2.5478936378387824e-11
Monomer-Open,9.960864885018117,445,k,scaling_factor9_6,814295.985616204±20022.290805750647,6.742600699993773e-09±2.5434593949459923e-11
Monomer-Closed,5.85016471662435,445,k,scaling_factor9_6,682372.8097007186±14997.115739373243,6.196022805937673e-09±2.2013561903380327e-11
Open-Closed,86.8689571695128,445,k,scaling_factor5_2,1.199040866595169e-14±9.4537826418271e-05,2.0138191114682513e-09±2.281652089653423e-11
Monomer-Open,2.8257121211113994,445,k,scaling_factor5_2,1547449.3836884098±28842.397965696815,3.734792253240471e-09±1.1312876122021888e-11 | {
"domain": "codereview.stackexchange",
"id": 44996,
"lm_label": null,
"lm_name": null,
"lm_q1_score": null,
"lm_q1q2_score": null,
"lm_q2_score": null,
"openwebmath_perplexity": null,
"openwebmath_score": null,
"tags": "python",
"url": null
} |
python
Monomer-Closed,2.288890413176619,445,k,scaling_factor5_2,1358226.1301473703±25519.081777683383,3.4869380716173737e-09±1.1630345511165903e-11
Open-Closed,44.03075685651836,445,k,scaling_factor2_9,7.596616669047762e-10±0.03825540478147579,9.78547465280144e-10±1.3430616960734352e-11
Monomer-Open,1.3557306369249709,445,k,scaling_factor2_9,2661460.3138776086±57647.801391141016,1.99787386634398e-09±6.74644817037137e-12
Monomer-Closed,1.409921506178703,445,k,scaling_factor2_9,2398616.885835869±57746.99771010116,1.8925880862497024e-09±7.982211380282759e-12
3-state_Single_Scale,57.615885203971736,2679,k,k1,scaling_factor,9762897846.641188±35156079427086.336,1.7118456236309143e-05±0.0620830798976208,1.7981046207538043e-08±7.510816000548932e-11
3-state_Individual_Scale,2.230352652064203,2674,k,k1,scaling_factor19_5,scaling_factor1_3999999999999997,scaling_factor0_8000000000000002,scaling_factor9_6,scaling_factor5_2,scaling_factor2_9,346237.17724154366±10347.067877637079,0.5720329855421686±0.026830421803599746,2.033917101407212e-08±2.096493945233133e-11,9.917222598687658e-10±2.4103724827806476e-12,4.763518468564598e-10±2.1289611304197432e-12,9.100978415332861e-09±8.38803486597971e-12,4.662680463951574e-09±5.184293805864168e-12,2.346650207485368e-09±3.678959942031746e-12
3-state,4.168103487588879,444,k,k1,scaling_factor19_5,358814.34555294213±25330.86544610544,0.4782231359207625±0.04717568612503962,2.0252227672656886e-08±3.736455119218115e-11
3-state,1.1730500108145645,444,k,k1,scaling_factor1_3999999999999997,4813858.963224251±1935269.1802777958,0.4486170154080191±0.26919147372912244,9.833762693034487e-10±5.18418396203546e-12
3-state,1.4006404975119717,444,k,k1,scaling_factor0_8000000000000002,150933513.07607412±4268884459.5485096,0.00979541902064529±0.2800592393117337,4.573150746978172e-10±5.363590069092257e-12 | {
"domain": "codereview.stackexchange",
"id": 44996,
"lm_label": null,
"lm_name": null,
"lm_q1_score": null,
"lm_q1q2_score": null,
"lm_q2_score": null,
"openwebmath_perplexity": null,
"openwebmath_score": null,
"tags": "python",
"url": null
} |
python
3-state,3.2446868688627593,444,k,k1,scaling_factor9_6,638859.9303166413±33139.795151712024,0.6338696336960787±0.05411692582116822,9.105416420851498e-09±1.395974355015715e-11
3-state,1.5540000939874206,444,k,k1,scaling_factor5_2,1240799.333784847±82530.5587183448,0.7623234795289164±0.09194469661262392,4.699436617627839e-09±8.525691898493668e-12
3-state,1.194839975889669,444,k,k1,scaling_factor2_9,1918615.601806648±204979.40206127142,1.138829139404936±0.2713733742617552,2.3796051795699213e-09±6.837340721692228e-12
5-state_Single_Scale,57.63744302687018,2678,k,k1,k2,scaling_factor,13787856758.88831±77502393605450.58,5.633631339208023e-10±9.788156122114106e-06,21513.043860651043±288762324.10162944,1.7980996247501935e-08±7.876578950256246e-11
5-state_Individual_Scale,2.190443644137053,2673,k,k1,k2,scaling_factor19_5,scaling_factor1_3999999999999997,scaling_factor0_8000000000000002,scaling_factor9_6,scaling_factor5_2,scaling_factor2_9,520975155.21864897±338181983842.1005,1.872718763098626±1.3231414390362621,0.00036525469284254264±0.2384295617958695,2.0364478325873847e-08±2.2374940408026503e-11,9.871938821959247e-10±2.522415157507014e-12,4.73653116728201e-10±2.152602970247701e-12,9.099120346078848e-09±8.40461223140245e-12,4.655219765226093e-09±5.2883376739543374e-12,2.3397150883397444e-09±3.841126634107586e-12
5-state,4.041057734442511,443,k,k1,k2,scaling_factor19_5,2104011636.0595942±30717415296586.047,1.2619040946318276±4.550279721760602,9.93189372962e-05±1.4585880130631816,2.0259553590307178e-08±4.527290095991366e-11
5-state,1.175700390612788,443,k,k1,k2,scaling_factor1_3999999999999997,4813650.560787797±2858297.857550905,0.00010115948534594743±1.024280572653037,4435.322546847208±44606762.47283073,9.833760472588438e-10±5.226659109648795e-12
5-state,1.4038034641727541,443,k,k1,k2,scaling_factor0_8000000000000002,126233386.6313605±13096872320.36746,1.3359064470197524e-06±0.056717076796734496,8785.79540954556±368623673.1599917,4.5734660503171654e-10±5.4598593707430525e-12 | {
"domain": "codereview.stackexchange",
"id": 44996,
"lm_label": null,
"lm_name": null,
"lm_q1_score": null,
"lm_q1q2_score": null,
"lm_q2_score": null,
"openwebmath_perplexity": null,
"openwebmath_score": null,
"tags": "python",
"url": null
} |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.