Write / change raw ID3 tags? - id3

I have an MP3 file:
B{
255 251 144 100 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 73 110 102 111 0 0 0 15
0 0 30 161 0 50 3 66 0 3 5 8 10 13 15 18 20 24 26 28
31 33 36 38 41 43 47 49 52 54 56 59 61 64 66 69 72
75 77 79 82 84 87 89 92 95 98 100 103 105 107 110
112 115 118 ~3277535 more~
}
And I have some metadata I want to put in it:
H{
{ "title" "Superstar (feat. Krewella)" }
{ "artist" "Pegboard Nerds & NGHTMRE" }
{ "num" 1 }
}
Factor doesn't have a vocabulary to write ID3 tags (yet), but I have the raw file data and some data I'd like to write.
Wikipedia isn't any help, and the mpg123 source doesn't really clear anything up either.
How do I put the data from the hashtable into the ID3v2 header?

We don't have support for writing id3 tags yet. But python has and we have support for wrapping Python modules. So if you are willing to be pragmatic first sudo pip install mutagen then:
USING: kernel python python.syntax sequences ;
IN: examples.python.mutagen
PY-QUALIFIED-FROM: mutagen.easyid3 => EasyID3 ( name -- obj ) ;
PY-METHODS: mutagen:easyid3:EasyID3 =>
__setitem__ ( self key value -- )
save ( self -- ) ;
: <EasyID3> ( str -- easyid3 )
>py mutagen.easyid3:EasyID3 ;
: setitem ( obj key val -- )
[ >py ] bi# __setitem__ ;
: update-tags ( easyid3 assoc -- )
dupd [ first2 setitem ] with each save ;
Then you can write id3 tags like this:
[
"/path/to/mp3-file.mp3" <EasyID3>
{
{ "title" "Superstar (feat. Krewella)" }
{ "artist" "Pegboard Nerds & NGHTMRE" }
} update-tags
] with-destructors
Of course doing it in pure Factor isn't impossible. But you would have to study up on the mp3 and id3v1-2 specifications.

Related

Find Optimal solution to a function

I have the following Dataframe called df_cam_cb_days:
3m 6m 9m 1y 18m 24m Effective
2021-03-30 49 49 49 49 49 49 2021-03-31
2021-05-13 40 44 44 44 44 44 2021-05-14
2021-06-08 0 26 26 26 26 26 2021-06-09
2021-07-14 0 36 36 36 36 36 2021-07-15
2021-08-31 0 26 48 48 48 48 2021-09-01
2021-10-13 0 0 43 43 43 43 2021-10-14
2021-12-14 0 0 27 62 62 62 2021-12-15
2022-01-26 0 0 0 43 43 43 2022-01-27
2022-03-30 0 0 0 14 63 63 2022-03-31
2022-05-11 0 0 0 0 42 42 2022-05-12
2022-06-08 0 0 0 0 28 28 2022-06-09
2022-07-13 0 0 0 0 35 35 2022-07-14
2022-08-31 0 0 0 0 27 49 2022-09-01
2022-10-12 0 0 0 0 0 42 2022-10-13
2022-12-14 0 0 0 0 0 63 2022-12-15
2023-01-25 0 0 0 0 0 42 2023-01-26
2023-02-10 0 0 0 0 0 15 2023-02-11
and I have the following function that receives the DataFrame and an array:
mon_policy =np.array([.5,
.75,
.75,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1])
#returns numpy array with Breakeven info
def cam_be_mon(mp,df):
columns = ['3m','6m','9m','1y','18m','24m']
days_array = np.array([0,0,0,0,0,0])
days_array = df_cam_cb_days[columns].sum(axis=0).values
data_array= df_cam_cb_days[columns].values.T
c= np.log(mp/36000+1)
be = np.dot(data_array,c)
be = (np.exp(be[0:])-1)*36000/days_array
return be
target = np.array([.3525,.415,.475,.56,.715,.916366])
cam_be_mon(mon_policy,df_cam_cb_days)
The Function as is returns the solution: array([0.61281788, 0.76943154, 0.84886388, 0.88890188,
0.92955637, 0.95151633])
I need to find the set of <mon_policy> that returns a solution = to target , or the closest if there is no solution.
I found the answer with scipy.optimize

Convert Glyph path to SVG

I have the following glyph path:
<glyph glyph-name="right-nav-workflow" unicode="" d="M251 101c0 65 0 131 0 196 26 0 52 0 78 0 0 27 0 54 0 81-29 7-52 23-67 50-11 20-14 41-10 64 8 45 48 79 92 81 49 1 88-29 102-79 2 0 4 0 6 0 20 0 40 0 60 0 5 0 8 1 11 5 32 32 64 64 96 96 2 1 3 3 4 4 42-42 84-84 127-127-1 0-2-2-4-4-32-32-65-65-98-98-2-2-4-6-4-10 0-21 0-43 0-64 30-8 53-24 67-52 12-21 15-44 9-68-11-46-55-78-102-75-48 3-88 42-92 91-4 48 28 91 78 104 0 1 1 3 1 4 0 21 0 42 0 62 0 3-2 5-3 7-28 28-55 55-83 83-1 1-3 3-5 3-22 0-45 0-68 0-5-19-13-36-27-50-14-14-31-23-50-27 0-27 0-53 0-81 26 0 52 0 78 0 0-65 0-130 0-196-65 0-131 0-196 0z m157 156c-40 0-79 0-118 0 0-39 0-78 0-117 40 0 79 0 118 0 0 39 0 78 0 117z m275-58c0 33-26 59-59 59-32 0-59-26-59-59 0-33 27-59 60-59 32 0 58 26 58 59z m-334 216c33 0 59 27 59 59 0 33-26 59-59 59-33 0-59-26-59-59 0-33 26-59 59-59z m275-11c23 23 46 46 69 69-23 23-47 46-69 68-23-22-46-46-69-69 23-22 46-45 69-68z" horiz-adv-x="1000" />
How can I convert this into SVG? I tried to save it in a text file with svg extension but seems is not working.
Take the raw drawing data, put it in a path element, remove the glyph specific attributes, add an appropriate viewBox. Now you have something that works as an inline SVG. If you want to save it as a standalone SVG, then you need to add a name space declaration.
<svg height="400px" width="400px" viewBox="0 0 1000 1000">
<path transform="scale(1,-1) translate(0,-650)" fill="none" stroke="red" stroke-width="1" d="M251 101c0 65 0 131 0 196 26 0 52 0 78 0 0 27 0 54 0 81-29 7-52 23-67 50-11 20-14 41-10 64 8 45 48 79 92 81 49 1 88-29 102-79 2 0 4 0 6 0 20 0 40 0 60 0 5 0 8 1 11 5 32 32 64 64 96 96 2 1 3 3 4 4 42-42 84-84 127-127-1 0-2-2-4-4-32-32-65-65-98-98-2-2-4-6-4-10 0-21 0-43 0-64 30-8 53-24 67-52 12-21 15-44 9-68-11-46-55-78-102-75-48 3-88 42-92 91-4 48 28 91 78 104 0 1 1 3 1 4 0 21 0 42 0 62 0 3-2 5-3 7-28 28-55 55-83 83-1 1-3 3-5 3-22 0-45 0-68 0-5-19-13-36-27-50-14-14-31-23-50-27 0-27 0-53 0-81 26 0 52 0 78 0 0-65 0-130 0-196-65 0-131 0-196 0z m157 156c-40 0-79 0-118 0 0-39 0-78 0-117 40 0 79 0 118 0 0 39 0 78 0 117z m275-58c0 33-26 59-59 59-32 0-59-26-59-59 0-33 27-59 60-59 32 0 58 26 58 59z m-334 216c33 0 59 27 59 59 0 33-26 59-59 59-33 0-59-26-59-59 0-33 26-59 59-59z m275-11c23 23 46 46 69 69-23 23-47 46-69 68-23-22-46-46-69-69 23-22 46-45 69-68z"/>
</svg>
Update - Robert points out that the SVG Fonts spec has a y axis (0 on the bottom) that's inverted from the SVG norm (0 is the top) -> so you also need to flip the drawing along the x axis by using a scale (1,-1).

Find duplicate content and consolidate in groovy

I want to edit a file automatically with groovy.
For example, i have the following textfile:
(First line is only for your understanding)
branch ID item ID - - weight piece --- --- ---
178568305 108350 0 0 0 -1 215 215 012
178568305 102190 0 0 0 -1 74 74 012
178568305 102120 0 0 0 -8 35 35 012
178568305 102190 0 0 0 -6 74 74 012
178568305 102190 0 0 0 -6 74 74 012
178587626 108280 0 0 0 -3 189 189 012
178587626 159550 0 0 0 -1 499 499 012
178587626 107740 0 0 0 -4 229 229 012
178587626 105330 0 0 -10 0 626 626 012
178587626 102190 0 0 0 -6 74 74 012
In column 1 i have a brach ID
In column 2 i have a item ID
In column 5 i have a weight, for example in gram
In column 6 i have a number of pieces
Column 3, 4, 7, 8 and 9 are not important
In branch ID:
From line 1 to 5 and 6 and from 6 to 10 i have two different branchs IDs
In item ID:
In line 2, 4 and 5 i have the same item ID always to the same branche ID.
Now, what i want is to consolidate the the item ID 102190 with branch ID 178568305 to one line.
But the piece or weight have to count in sum in these one line.
But attention: In Line 10 i have the same item ID like in Line 2 or 4, but i have a another branch ID. It is not allowed to consolidate the weight/piece from line 10 with 2, 4 and 5!
For Example:
branch ID item ID - - weight piece --- --- ---
178568305 108350 0 0 0 -1 215 215 012
178568305 102120 0 0 0 -8 35 35 012
178568305 102190 0 0 0 -13 74 74 012
178587626 108280 0 0 0 -3 189 189 012
178587626 159550 0 0 0 -1 499 499 012
178587626 107740 0 0 0 -4 229 229 012
178587626 105330 0 0 -10 0 626 626 012
178587626 102190 0 0 0 -6 74 74 012
My input text file is only separated with spaces. My output textfile must be exact the same.
Unfortunately, I have no idea how to create this in a groovy script.
Can anyone help? Tutorials are helpful too. I have no idea for the logical script expiration.
You just need to group the data by branchId and itemId, here is a working code for you:
def input = new File("input.txt")
def output = new File("output.txt")
PrintWriter printWriter = new PrintWriter(output)
Map<String, String[]> result = [:]
input.eachLine { currentLine, lineNumber ->
def array = currentLine.split(" +");
String rowId = array[0] + "_" + array[1];
if(lineNumber == 1 ){
result.put(rowId, array)
}else {
String[] rowValues = array;
if(null != result.get(rowId)){
String[] existingValues = result.get(rowId);
for(int i = 0; i < existingValues.length; ++i){
try{
existingValues[i] = String.valueOf( rowValues[i].toInteger() + existingValues[i].toInteger())
}catch (NumberFormatException ex){
print(ex)
}
}
}else{
result.put(rowId, rowValues)
}
println(array)
}
}
int maxColumnWidth = 14;
result.each { key, value ->
for(int i = 0; i < value.length; ++i){
if(i == 0){
printWriter.print(value[i])
}else{
String v = value[i];
while(v.length() < maxColumnWidth){
v = " " + v;
}
printWriter.print(v)
}
}
printWriter.println()
}
printWriter.close()
Sample Input:
branch ID item ID - - weight piece --- --- ---
178568305 108350 0 0 0 -1 215 215 012
178568305 102190 0 0 0 -1 74 74 012
178568305 102120 0 0 0 -8 35 35 012
178568305 102190 0 0 0 -6 74 74 012
178568305 102190 0 0 0 -6 74 74 012
178587626 108280 0 0 0 -3 189 189 012
178587626 159550 0 0 0 -1 499 499 012
178587626 107740 0 0 0 -4 229 229 012
178587626 105330 0 0 -10 0 626 626 012
178587626 102190 0 0 0 -6 74 74 012
Output:
branch ID item ID - - weight piece --- --- ---
178568305 108350 0 0 0 -1 215 215 012
535704915 306570 0 0 0 -13 222 222 36
178568305 102120 0 0 0 -8 35 35 012
178587626 108280 0 0 0 -3 189 189 012
178587626 159550 0 0 0 -1 499 499 012
178587626 107740 0 0 0 -4 229 229 012
178587626 105330 0 0 -10 0 626 626 012
178587626 102190 0 0 0 -6 74 74 012

SAS: Creating separate histograms on one page and producing plot for value combinations

Column 1:
Flu Shot Status
Column 2:
Age
Column 3:
Health Awareness Index
Column 4:
Gender
0 59 52 0
0 61 55 1
1 82 51 0
0 51 70 0
0 53 70 0
0 62 49 1
0 51 69 1
0 70 54 1
0 71 65 1
0 55 58 1
0 58 48 0
0 53 58 1
0 72 65 0
0 56 68 0
0 56 83 0
That's my dataset above and what I want to do is the following
a) Produce a single plot of Health Awareness Index (HAI) and Age for each value combination of Gender and Flu Shot Status and
(I'm not so sure how to do this at all; a few hints about where to start would really help)
b) Produce separate histograms for the variable Health Awareness Index by Flu Shot Status for Males between the Ages of 50 and 70 (including both 50 and 70). Give the histogram a title and color the bars using different colors for each histogram. Here's my code:
First I will set up a permanent library, as the dataset is titled hw3data.sas:
libname di “c:\flu”;
data di.HW3 Data;
infile hw3data.sas;
input FluShotStatus Age HAI Gender;
run;
proc sort data=di.hw3
by age;
run;
data=di.hw3
if age=50 to 70
run;
proc univariate data=Steel;
var HAI FluShotStatus;
histogram FluShotStatus;
run;
I'm not so sure how to insert the normal distribution curve here and I guess I could really use some help
You don't clearly specify what type of plot you're looking for, so I'm going to assume at this point you're looking for a scatter plot, by age and gender combinations. Here's an example that utilizes PROC SGPLOT which is a good graphical procedure for generating SAS graphs.
data have;
input flu age hai gender;
cards;
0 59 52 0
0 61 55 1
1 82 51 0
0 51 70 0
0 53 70 0
0 62 49 1
0 51 69 1
0 70 54 1
0 71 65 1
0 55 58 1
0 58 48 0
0 53 58 1
0 72 65 0
0 56 68 0
0 56 83 0
;
run;
proc sort data=have;
by flu gender;
run;
proc sgplot data=have;
by flu gender;
scatter x=age y=hai;
label age='Age' hai='Health Awareness Index';
run;quit;

Grep rows with a length of 3

Hi i have a table which looks like this:
chr10 84890986 84891021 2 17.5 2 93 0 61 48 2 48 0 1.16 GA
chr10 84897562 84897613 2 25.5 2 100 0 102 50 49 0 0 1 AC
chr10 84899819 84899844 2 12.5 2 100 0 50 0 0 52 48 1 GT
chr10 84905282 84905318 6 5.8 6 87 6 54 80 19 0 0 0.71 AAAAAC
chr10 84955235 84955267 2 16 2 100 0 64 50 0 0 50 1 AT
chr10 84972254 84972288 2 17 2 93 0 59 2 0 47 50 1.16 GT
chr10 85011399 85011478 3 25.7 3 80 12 63 58 1 40 0 1.06 GAA
chr10 85011461 85011525 3 20.7 3 87 6 74 39 0 60 0 0.97 GAG
chr10 85014721 85014841 5 23.8 5 78 8 66 0 69 0 29 1 TTCCC
chr10 85021530 85021701 5 38.4 5 84 13 53 74 0 24 0 0.85 AAGAG
chr10 85045413 85045440 3 9 3 100 0 54 66 33 0 0 0.92 CAA
chr10 85059334 85059364 5 6 5 92 0 51 20 3 0 76 0.92 ATTTT
chr10 85072010 85072038 2 14 2 100 0 56 50 50 0 0 1 CA
chr10 85072037 85072077 4 10 4 84 10 55 25 22 0 52 1.47 ATCT
chr10 85084308 85084338 6 5 6 91 0 51 83 13 3 0 0.77 CAAAAA
chr10 85096597 85096640 3 14.7 3 95 4 79 69 30 0 0 0.88 AAC
chr10 85151154 85151190 6 6.5 6 87 12 51 0 11 0 88 0.5 TTTCTT
chr10 85168255 85168320 4 16.2 4 100 0 130 50 0 49 0 1 AGGA
chr10 85173155 85173184 2 14.5 2 100 0 58 48 0 0 51 1 TA
chr10 85196836 85196861 2 12.5 2 100 0 50 52 48 0 0 1 AC
chr10 85215511 85215546 2 17.5 2 100 0 70 51 48 0 0 1 AC
chr10 85225048 85225075 2 13.5 2 100 0 54 51 48 0 0 1 AC
chr10 85242322 85242357 2 17.5 2 93 0 61 0 2 48 48 1.16 TG
chr10 85245934 85245981 4 11 4 79 20 51 27 2 0 70 0.99 ATTT
chr10 85249139 85249230 5 18.8 5 88 6 116 0 60 0 39 0.97 TTCCC
chr10 85251100 85251153 5 11 5 97 2 92 0 0 37 62 0.96 GTTTG
chr10 85268725 85268752 4 6.8 4 100 0 54 0 25 0 74 0.83 CTTT
chr10 85268767 85268798 4 7.8 4 100 0 62 0 0 22 77 0.77 TTTG
chr10 85269189 85269239 6 8.8 6 79 16 54 84 2 12 2 0.8 AAAAGA
chr10 85330217 85330253 2 18 2 100 0 72 0 0 50 50 1 TG
chr10 85332256 85332314 4 15 4 82 7 75 70 1 27 0 0.97 AAGA
chr10 85337969 85337996 2 13.5 2 100 0 54 0 0 48 51 1 TG
chr10 85344795 85344957 2 75.5 2 83 12 198 45 4 3 45 1.42 TA
chr10 85349732 85349765 5 6.8 5 93 6 59 84 15 0 0 0.61 AAAAC
chr10 85353082 85353109 5 5.4 5 100 0 54 0 22 18 59 1.38 CTGTT
I want to extract all rows with have 3 and only 3 characters in the last column. My try till now is this:
grep -E "['ACTG']['ACTG']['ACTG']{1,3}$"
But this gives me everything from 3 and longer than 3. I tried many different combinations but nothing seems to give me what i want. Any ideas?
If you like to try awk, you can do:
awk '$NF~/\<...\>/' file
chr10 85011399 85011478 3 25.7 3 80 12 63 58 1 40 0 1.06 GAA
chr10 85011461 85011525 3 20.7 3 87 6 74 39 0 60 0 0.97 GAG
chr10 85045413 85045440 3 9 3 100 0 54 66 33 0 0 0.92 CAA
chr10 85096597 85096640 3 14.7 3 95 4 79 69 30 0 0 0.88 AAC
It will test if last field $NF has 3 character ...
This regex would also do: awk '$NF~/^...$/'
Or if you need exact characters. (PS this needs awk 4.x, or use of switch --re-interval)
awk '$NF~/^[ACTG]{3}$/' file
Using grep
grep -E " [ACTG]{3}$" file
chr10 85011399 85011478 3 25.7 3 80 12 63 58 1 40 0 1.06 GAA
chr10 85011461 85011525 3 20.7 3 87 6 74 39 0 60 0 0.97 GAG
chr10 85045413 85045440 3 9 3 100 0 54 66 33 0 0 0.92 CAA
chr10 85096597 85096640 3 14.7 3 95 4 79 69 30 0 0 0.88 AAC
You need the space, to separate last column, and {3} to get 3 and only 3 characters.
If you want to print the rows which has exactly three chars in the last column then you could use the below grep command.
grep -E " [ACTG]{3}$"
[ACTG]{3} Matches exactly three characters from the given list.
You have to grep either " ['ACTG']['ACTG']['ACTG']$" or " ['ACTG']{1,3}$".
Currently, you are grepping 3 to 5 'ACTG'.
Also, the quotes are unnecessary ['ACTG'] means "match anything between []" so any of the 5 characters 'ACTG, just grep " [ACTG]{1,3}$".
Be sure to use a delimiter for the left part (space ' ', tab\t if it is tab delimited, word boundary \b or \W).
If your lines are all ending with [ACTG]+, you can even only grep -E "\W.{,3}$"
Another way that you could do this would be using awk:
$ awk '$NF ~ /^[ACTG][ACTG][ACTG]$/' file
chr10 85011399 85011478 3 25.7 3 80 12 63 58 1 40 0 1.06 GAA
chr10 85011461 85011525 3 20.7 3 87 6 74 39 0 60 0 0.97 GAG
chr10 85045413 85045440 3 9 3 100 0 54 66 33 0 0 0.92 CAA
chr10 85096597 85096640 3 14.7 3 95 4 79 69 30 0 0 0.88 AAC
This prints all lines whose last field exactly matches 3 of the characters "A", "C", "T" or "G".
2 hours late but this is one way in awk
This can be easily edited for different lengths and fields.
awk 'length($NF)==3' file
As i was looking for answers myself i found out that Perl regex work more efficiently:
this does the deal : grep -P '\t...$' Way more compact code.
$ cat roi_new.bed | grep -P "\t...$"
chr10 81038152 81038182 3 9.7 3 92 7 51 30 0 0 70 0.88 TTA
chr10 81272294 81272320 3 8.7 3 100 0 52 0 30 69 0 0.89 GGC
chr10 81287690 81287720 3 10 3 100 0 60 66 33 0 0 0.92 CAA

Resources