Categories
Mastering Development

Filling in non-existing rows in R + dplyr

Apologies if this is a duplicate question, I saw some questions which were similar to mine, but none exactly addressing my problem. My data look basically like this: FiscalWeek <- as.factor(c(45, 46, 48, 48, 48)) Group <- c("A", "A", "A", "B", "C") Amount <- c(1, 1, 1, 5, 6) df <- tibble(FiscalWeek, Group, Amount) df […]

Categories
Database Development

Is it bad practice to calculate within the insert query?

I am trying to do a web application for time sheets. I have three options to calculate the value of hours (AFAIK): In the form In the backend In the query Is it smart or bad practice to do this calculation in the SQL query? with list as (select code_id,code_ppu from code) insert into hr […]

Categories
Mastering Development

xarray reverse interpolation (on coordinate, not on data)

I have a the following DataArray arr = xr.DataArray([[0.33, 0.25],[0.55, 0.60],[0.85, 0.71],[0.92,0.85],[1.50,0.96],[2.5,1.1]],[(‘x’,[0.25,0.5,0.75,1.0,1.25,1.5]),(‘y’,[1,2])]) This gives the following output <xarray.DataArray (x: 6, y: 2)> array([[0.33, 0.25], [0.55, 0.6 ], [0.85, 0.71], [0.92, 0.85], [1.5 , 0.96], [2.5 , 1.1 ]]) Coordinates: * x (x) float64 0.25 0.5 0.75 1.0 1.25 1.5 * y (y) int32 1 2 […]

Categories
Development

FFMPEG – How to resize an image overlay?

I need to resize input 3 (logo.gif) to 360×360, but using scale=360:360 just made my video quality really bad. Here’s my code: ffmpeg -y -hide_banner -safe 0 -f concat -i “concat.txt” -i “overlay.png” -i “audio.mp3” -ignore_loop 0 -i “logo.gif” -filter_complex “[0]scale=3840×2160,zoompan=z=’if(lte(zoom,1.0),1.25,max(1.001,zoom-0.0012))’:x=’iw/2-(iw/zoom/2)’:y=’ih/2-(ih/zoom/2)’:fps=20:d=200:s=1920×1080[p];[p][1]overlay, scale=1920:1080, drawtext=fontfile=Heathergreen.otf:text=TITLE’:fontcolor=black:fontsize=62:x=135:y=940, drawtext=fontfile=voxbox.ttf:text=’TEXT’:fontcolor=white:fontsize=70:x=120:y=885[v];[2:a]showwaves=mode=cline:s=178×56:r=20:scale=sqrt:colors=0x222222,colorkey=0x000000:0.01:0.1,format=yuva420p[w];[v][3]overlay=20:500[z];[z][w]overlay=108:740[outv]” -map “[outv]” -map 2:a -pix_fmt yuv420p -c:v libx264 -c:a aac -preset […]

Categories
Development

Colour a Q-Q plot comparing two distributions by quartiles in R

I am trying to construct a Q-Q plot comparing two distributions, with the 99th percentile colored like the following example: However I am not sure how to achieve this, here is a subset of my data: dfw <- structure(list(Date.Time = structure(c(848502000, 848509200, 848512800, 848520000, 848523600, 848530800, 848534400, 848541600, 848545200, 848552400, 848556000, 848563200, 848566800, 848574000, 848577600, […]

Categories
Development

How can I iterate a function over specific columns of a series of dataframes where I can set the order?

I work for an insurance company and I am trying to improve something that I built. I have about 150 data frames that look like this: library(data.table) dt_Premium<-data.table(Policy = c(“Pol123″,”Pol333″,”Pol555″,”Pol999”), Base_Premium_Fire= c(45,55,105,92), Base_Premium_Water= c(20,21,24,29), Base_Premium_Theft= c(3,5,6,7)) dt_Discount_Factors<-data.table(Policy = c(“Pol123″,”Pol333″,”Pol555″,”Pol999”), Discount_Factor_Fire= c(.9,.95,.99,.97), Discount_Factor_Water= c(.8,.85,.9,.96), Discount_Factor_Theft= c(1,1,1,1)) dt_Territory_Factors<-data.table(Policy = c(“Pol123″,”Pol333″,”Pol555″,”Pol999”), Territory_Factor_Fire= c(1.9,1.2,.91,1.03), Territory_Factor_Water= c(1.03,1.3,1.25,1.01), Territory_Factor_Theft= c(1,1.5,1,.5)) dt_Fixed_Expense<-data.table(Policy […]

Categories
Development

visualization clusterization results

After using k-means i have 3 clusters. I’ve used 10 features (marks) in k-means for this data set. I’m understand that we can’t draw 10D chart, but how can i visualize this clusters? Should i separate data by 2 or 3 features instead 10? What axises should i use in my case? For drawing i’m […]

Categories
CSS Development

Animate (draw) SVG Fotography paths and fill, using CSS (JS)

So, I wanted to animate a huge SVG photography, I have done it a year ago but have lost track of how I have done it. The SVG inside the given code part is not the full image since it has too many characters… but you’ll get the sence of the scale and structure by […]

Categories
Development

Use a for loop to calculate and print the average of the third list items in a dictionary

I have the following dictionary and am looking to calculate and print the average of all prices (3rd item in each list): right now I have each list item recalled to find the value. This is simple to do for a short dictionary but I am hoping there is a shorter/simpler way to do this […]

Categories
Development

Keras image classification: High accuracy shown but low on test images

I’m trying to do some image classification on the Caltech101 dataset. I used several pretrained models in Keras. I used some augmentation on the training set: train_datagen = keras.preprocessing.image.ImageDataGenerator( rescale=1./255, rotation_range=15, width_shift_range=0.1, height_shift_range=0.1, shear_range=0.01, zoom_range=[0.9, 1.25], horizontal_flip=False, vertical_flip=False, fill_mode=’reflect’, data_format=’channels_last’, brightness_range=[0.5, 1.5]) validation_datagen = keras.preprocessing.image.ImageDataGenerator(rescale=1./255) train_generator = train_datagen.flow_from_directory( train1_dir, # Source directory for the training […]