StackOverflow.com

VN:F [1.9.22_1171]
Rating: 8.5/10 (13 votes cast)

Random snippets of all sorts of code, mixed with a selection of help and advice.

How to reliably calculate rolling metrics when the dataset contains missing values in Python?

2 December 2025 @ 3:04 am

I’m working on a data analytics project where I need to calculate rolling averages and rolling sums on a dataset that has missing values in some numeric columns. Example: date,value 2024-01-01,10 2024-01-02, 2024-01-03,15 2024-01-04,20 2024-01-05, My current code: import pandas as pd df = pd.read_csv("data.csv", parse_dates=["date"]) df = df.sort_values("date") df["rolling_avg"] = df["value"].rolling(window=3).mean() df["rolling_sum"] = df["value"].rolling(window=3).sum() The issue is that the results include NaN whenever there are missing values, and I’m not sure what the best practice is: My questions: Should missing values be filled, ignored, or interpolated before calculating rolling metrics? Is there a recommended method for time-series analytics where missing values are common? Does pandas provide a built-i

Why big data log cause the java progress memory high?

2 December 2025 @ 3:03 am

problem--why the big log data cause the jvm memory go high? memory problem top res problem: the java process is using more and more memory over time. jvm argument:java -Xmx5120M -Xms5120M -XX:NewRatio=1 -XX:MetaspaceSize=512m -XX:MaxMetaspaceSize=512m -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=/data/log -XX:+PrintCommandLineFlags -XX:+PrintGCDetails -XX:+PrintGCDateStamps -XX:+PrintGCTimeStamps -Xloggc:/data/log/gc-%t.log -XX:+UseGCLogFileRotation -XX:NumberOfGCLogFiles=5 -XX:GCLogFileSize=20m -XX:ErrorFile=/data/log/hs_err_%p.log -XX:+UseConcMarkSweepGC -XX:CMSInitiatingOccupancyFraction=80 -XX:+UseCMSInitiatingOccupancyOnly -XX:AutoBoxCacheMax=20000 -XX:-UseBiasedLocking -XX:NativeM

Data Ownership and Transaction Managment in SOA

2 December 2025 @ 3:02 am

I'm trying to learn more about Service Oriented Architecture as to me, it seems like a good middle ground between monolithic and micro service applications. Please correct me if I'm wrong but the primary goal is to segment domains (business logic) into separated independent services that are still wrapped by an overarching build orchestrator. From my perspective, even though the domains are separated and independent, that doesn't necessarily mean that each domain should control an independent persistent layer, instead they should share a persistent layer to share referential integrity and maintain easy querying. This leads me to my primary questions: If there are multiple independent services that are all making transactions to the db, how do you ensure that if there is a failure in a downstream process, how do you properly manage the rollback of the previous transactions? Do you just literally chain try catches from the start all

Trigger Function to check record uniqueness

2 December 2025 @ 2:54 am

I have a trigger in Postgresql 13 like this to prevent duplicate entry on one of the coloumn : This trigger is used in Arcgis Field Map apps. CREATE OR REPLACE FUNCTION xxx_check_unique() RETURNS TRIGGER AS $$ BEGIN IF (SELECT EXISTS(SELECT FROM schema1.chamber where id = new.id)) = 'false' THEN //check RETURN new; //if no duplicate exist, enter this value else RAISE INFO '% DUP', new.id; return null; //if there is duplicate, do nothing end if; END; $$ LANGUAGE plpgsql; CREATE OR REPLACE TRIGGER xx_check_unique BEFORE update of id ON schema1.chamber FOR EACH ROW EXECUTE PROCEDURE xxx_check_unique(); CREATE OR REPLACE TRIGGER xx_check_unique BEFORE insert ON schema1.chamber FOR EACH ROW EXECUTE PROCEDURE xxx_check_unique(); Question : Is the part "RETURN NULL" correct ? This part is causing the Field Map to return an error if a

Troubleshooting memory leak / retain cycle in Apple's camera app tutorial

2 December 2025 @ 2:48 am

I'm following along this camera tutorial from Apple: https://developer.apple.com/tutorials/sample-apps/capturingphotos-camerapreview I have a DataModel: final class DataModel: ObservableObject { let camera = Camera() @Published var frame: Image? var isPhotosLoaded = false init() { print("DataModel init") Task { await handleCameraPreviews() } } deinit { print("DataModel deinit") } func handleCameraPreviews() async { let imageStream = camera.previewStream .map { $0.image } for await image in imageStream { Task { @MainActor in // CIFilters to come... frame = image } } } } And the Camera: class Cam

Calculate how many hours are available based on multiple approvals with varying start and end dates and hours spent

2 December 2025 @ 2:47 am

I have a client who issues approvals (as a letter) to spend time on specific projects in specific codes. Like: Approval No: R124-18 Project: A Date: 2/12/2024 Start: 2/12/2024 End: 2/03/2025 Code: alpha 124: 12 hours alpha 592: 8 hours alpha 593: 6 hours We capture this in an "Approvals" table like this (one project only shown for clarity): Date Start End Project Approval No Code Hours 2/12/2024 2/12/2024 2/03/2025 A R124-18 alpha 124 12 2/12/2024 2/12/2024 2/03/2025 A R124-18 alpha 592 8 2/12/2024 2/12/2024 2/03/2025 A R124-18 alpha 593 6 19/02/2025

Reverse an Array by recursion using swap in python

2 December 2025 @ 2:46 am

so I was trying to reverse an array by recursion so the code logic is we are swaping right most end value to the left most end. I have implemented logic but the thing is My recursion function retuns None when I explicity wants to return the reversed array. so I wanna know why it is returning None when I was trying to return an array. I have given a code below so please someone can explain me why it is happening and thank you in advance def reverse_array(left,right,array): if left > right: return array swap = 0 swap = array[left] array[left] = array[right] array[right]=swap reverse_array(left+1,right-1,array) array = [1,2,3,4,5] print(reverse_array(0,4,array))

MySQL 8 query always returns the full list instead of missing records when comparing against existing table

2 December 2025 @ 2:45 am

I’m working with MySQL 8.0.35 on DBeaver app and trying to compare a list of books in Spanish (title + author) against my table libros, which has two columns: titulo and autor. My goal is to return only the books that do NOT already exist in the libros table. I'm not fully acquainted with SQL queries and asked ChatGPT to generate a large inline table using SELECT ... UNION ALL ...: SELECT t.titulo, t.autor FROM ( SELECT 'Cuentos Del Hambre' AS titulo, '' AS autor UNION ALL SELECT 'Limites Existenciales', 'A.A.Genie' UNION ALL SELECT 'En Casa De Ana Los Arboles No Tienen La Culpa', 'Andira Watson' -- (over +100 more rows) ) AS t LEFT JOIN libros c ON LOWER(c.titulo) = LOWER(t.titulo) AND LOWER(c.autor) = LOWER(t.autor) WHERE c.titulo IS NULL; However, it's failed to return the list of books not already present on the table 'libros'.

Why can std::string only create a constexpr object if it's a static variable?

2 December 2025 @ 2:37 am

I'm wondering why std::string can't be constexpr if it's a stack variable: #include <string> #include <iostream> #include <cstring> constexpr std::string str15 {"123456789012345"}; // THIS COMPILES struct Foo { constexpr Foo() : a(6) { for (int i = 0; i < 8; ++i) buff[i] = 0; } int a; char buff[8]; }; constexpr void func() { constexpr Foo f{}; // THIS COMPILES constexpr std::string str15 {"123456789012345"}; // THIS DOESN'T COMPILE } int main() { func(); return 0; } error: 'std::string{std::__cxx11::basic_string<char>::_Alloc_hider{((char*)(& str15.std::__cxx11::basic_string<char>::<anonymous>.std::__cxx11::basic_string<char>::<unnamed union>::_M_local_buf))}, 15, std::__cxx11::basic_string<char>::<unnamed union>{char [16]{'1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '1', '2', '3', '4', '5', 0}}}' is not

NumPy generate a 2d linear array using multiple values

2 December 2025 @ 2:37 am

So I'm trying to generate a map for a personal project using opensimplex noise, multiple layers etc. My problem is that I want to recreate the equator to combine with a temperature map to obviously make it colder at the poles and warmer in the middle, the issue is that I'm new to NumPy so I don't know how to do this. This is what I want the dataset to look like when it's returned [[-1, -1, -1, -1, -1, -1], [ -0.9, -0.9, -0.9, -0.9, -0.9], [ -0.8, -0.8, -0.8, -0.8, -0.8], ... ] So, each nested array would be filled with the same value, the reason I need this to recur like this is since I need to combine it with a noise map to make the middle warmer and the top and bottom colder. There is also the second issue that I'm not aware on how to solve of creating multiple "keypoints" of sorts, where the range would be, for example: -1, 1, -1, not just the range being from -1 to 1