Ubuntuのapt upgradeでUbuntu Proの通知がうざい

以下のメッセージがapt upgradeで表示される。肝心の必要な情報は見づらい。
以下のファイルをコメントアウトすると消える。

Get more security updates through Ubuntu Pro with 'esm-apps' enabled:
  python2.7-minimal imagemagick libjs-jquery-ui libopenexr25 libpostproc55
  libmagickcore-6.q16-6-extra libavcodec58 libmagickwand-6.q16-6 libavutil56
  imagemagick-6.q16 libswscale5 libmagickcore-6.q16-6 libswresample3
  imagemagick-6-common libavformat58 python2.7 libpython2.7-minimal
  libpython2.7-stdlib libavfilter7
sudo vi /etc/apt/apt.conf.d/20apt-esm-hook.conf
#APT::Update::Pre-Invoke {
#       "[ ! -e /run/systemd/system ] || [ $(id -u) -ne 0 ] || systemctl start --no-block apt-news.service esm-cache.service || true";
#};

#APT::Update::Post-Invoke-Stats {
#       "[ ! -f /usr/lib/ubuntu-advantage/apt-esm-hook ] || /usr/lib/ubuntu-advantage/apt-esm-hook || true";
#};

#binary::apt::AptCli::Hooks::Upgrade {
#       "[ ! -f /usr/lib/ubuntu-advantage/apt-esm-json-hook ] || /usr/lib/ubuntu-advantage/apt-esm-json-hook || true";
#};

Deapの遺伝子の1の出現数を固定する

from deap import tools,base,creator
import random

toolbox = base.Toolbox()
creator.create("FitnessMax", base.Fitness, weights=(1.0,))
creator.create("Individual", list, fitness=creator.FitnessMax)

saidai=30  ##1にする数

def makegene(container):
    hako=[0]*200
    sel=random.sample(range(len(hako)),saidai)
    for h in sel:
        hako[h]=1
    return container(hako)

toolbox.register("individual", makegene, creator.Individual)
#toolbox.register("individual", tools.initRepeat, creator.Individual, toolbox.attr_bool, 200)
ind=toolbox.individual()
print(ind)
[0, 0, 0, 0, 1, 0, 1, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
ind.count(1)
30

上記では、1が30個に固定されている。この数をランダムに1から30個までにする場合。

from deap import tools,base,creator
import random

toolbox = base.Toolbox()
creator.create("FitnessMax", base.Fitness, weights=(1.0,))
creator.create("Individual", list, fitness=creator.FitnessMax)

saidai=30 ##1から最大数saidaiまでにする

def makegene(container):
    hako=[0]*200
    sel=random.sample(range(len(hako)),random.randint(1,saidai))
    for h in sel:
        hako[h]=1
    return container(hako)

toolbox.register("individual", makegene, creator.Individual)
ind=toolbox.individual()
print(ind)
print(ind.count(1))

DEAP を使う

pythonにて遺伝的アルゴリズムを試してみる。
DEAP is a novel evolutionary computation framework

%%time

import random
import numpy
from deap import algorithms
from deap import base
from deap import creator
from deap import tools

creator.create("FitnessMax", base.Fitness, weights=(1.0,))
creator.create("Individual", list, fitness=creator.FitnessMax)
toolbox = base.Toolbox()
toolbox.register("attr_bool", random.randint, 0, 1)
toolbox.register("individual", tools.initRepeat, creator.Individual, toolbox.attr_bool, 200)
toolbox.register("population", tools.initRepeat, list, toolbox.individual)

def evalOneMax(individual):
    total=individual.count(1) ###1の個数を数える
    return(total),

toolbox.register("evaluate", evalOneMax)
toolbox.register("mate", tools.cxTwoPoint)
toolbox.register("mutate", tools.mutFlipBit, indpb=0.03)
toolbox.register("select", tools.selTournament, tournsize=3)

def main():
    random.seed(64) ##random Fix
    pop = toolbox.population(n=300)
    hof = tools.HallOfFame(1)
    stats = tools.Statistics(lambda ind: ind.fitness.values)
    #stats.register("avg", numpy.mean)
    #stats.register("std", numpy.std)
    stats.register("min", numpy.min)
    stats.register("max", numpy.max)

    algorithms.eaSimple(pop, toolbox, 0.5, 0.2, 50, stats, halloffame=hof)

    return pop

if __name__ == "__main__":
    pop=main()
    best_ind = tools.selBest(pop, 1)[0]
    print("Best individual is %s, %s" % (best_ind, best_ind.fitness.values))
gen nevals min max
0 300 78 120
1 187 89 122
2 157 96 127
3 176 99 129
.
.
.
49 178 174 189
50 187 172 189
Best individual is [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1], (189.0,)
CPU times: user 1.09 s, sys: 688 µs, total: 1.09 s
Wall time: 1.09 s

このパラメーターだと50世代で189になり、200が作られていない。algorithms.eaSimpleの50を300に増やすと200世代と少しで、200の個体が作られる
algorithms.eaSimple(pop, toolbox, 0.5, 0.2, 100, stats, halloffame=hof)

pandas.DataFrameを作る

indexにDatetimeIndexでdtype=’datetime64[ns]の値、Closeで100-190の値のDataFrameを作る

import pandas as pd

df_test=pd.DataFrame({
'Date':[
'2022-08-19 00:30:00',
'2022-08-19 00:45:00',
'2022-08-19 01:00:00',
'2022-08-19 01:15:00',
'2022-08-19 01:30:00',
'2022-08-19 01:45:00',
'2022-08-19 02:00:00',
'2022-08-19 02:15:00',
'2022-08-19 02:30:00',
'2022-08-19 02:45:00'],
'Close':[
100,
110,
100,
120,
140,
150,
120,
100,
180,
190]
}
)
df_i = df_test.set_index('Date')
df_i.index=pd.to_datetime(df_i.index)

中身をチェック。
class ‘pandas.core.frame.DataFrame’
DatetimeIndex: 10 entries, 2022-08-19 00:30:00 to 2022-08-19 02:45:00

df_i.info()

listに代入する
class ‘pandas._libs.tslibs.timestamps.Timestampになってる

list=[]
for da in df_i.index:
    print(type(da))
    list.append(da)

datetime型にする

type(list[0].to_pydatetime())

リストからdatetime型にする

for data in list:
    #print(type(data))
    time = data.to_pydatetime() # datetime型に変換
    #print(type(time))
    print(time)

Pandas Tips

ファイルをPanda DataFrameに読み込む

import pandas as pd

usecols = ['Date','Open','High','Low','Close','Volume']
file="~/sshmnt/candles_15m_bybit_BTC-USDT.csv"
data = pd.read_csv(file,names=usecols,parse_dates=True,index_col='Date')

print(len(data))

#data2=data[45700:45800]
#data2=data[46000-1000:46000]
#data2=data[0:59000]
data2=data.tail(120+4*24*1) ##1日分+120
print(len(data2))

data3=data2.copy()

close_data=data3["Close"]
close_data.plot()

列を追加

data3['Trend'] = 0
data3
#またはNaNを入れることも
data3['Trend'] = np.nan

列(Trend)を削除

data3.drop('Trend',axis=1)

列を抽出

#カラム1つ
data4["Close"]
#または
data4.Close
#カラムを2つ
data4[["Close","signal"]]

特定の行の表示、インデックスから

data3['2022-09-02 10:0:0' : '2022-09-02']

特定範囲の行(インデックス)の特定列に代入する(1)

data3['2022-09-02 10:0:0' : '2022-09-02']['Trend']=2

特定の範囲のindex行の、特定列に代入する。(2) *上記の(1)が動作しない場合

data3.loc['2022-09-01 09:00:00':'2022-09-01 23:0:0',"Trend"]=-1

atでこのようなスライスでの使い方はエラーがでるので使えない

data3.at['2022-09-01 09:00:00':'2022-09-01 23:0:0',"Trend"]=-1

特定範囲の抽出

ts= "2022-09-01 09:00:00"
ts2="2023-01-01 09:00:00"
data2= (data[ts : ts2])
data2

JupyterでPandasの表示設定

pd.set_option('display.max_columns', 10)
pd.set_option('display.max_rows', 300)

データフレームの作成、日付時間をインデックスに

df_test=pd.DataFrame({
'Date':[
'2022-08-19 00:30:00',
'2022-08-19 00:45:00',
'2022-08-19 01:00:00',
'2022-08-19 01:15:00',
'2022-08-19 01:30:00',
'2022-08-19 01:45:00',
'2022-08-19 02:00:00',
'2022-08-19 02:15:00',
'2022-08-19 02:30:00',
'2022-08-19 02:45:00']
}
)
df_i = df_test.set_index('Date')

上記ではインデックスが作れるが、dtypeがobjectになってる

df_i.index

Index(['2022-08-19 00:30:00', '2022-08-19 00:45:00', '2022-08-19 01:00:00',
'2022-08-19 01:15:00', '2022-08-19 01:30:00', '2022-08-19 01:45:00',
'2022-08-19 02:00:00', '2022-08-19 02:15:00', '2022-08-19 02:30:00',
'2022-08-19 02:45:00'],
dtype='object', name='Date')

上記をデイトタイムにするにはこれ

df_i.index=pd.to_datetime(df_i.index)

インデックスを見るとIndexがDatetimeIndexのdtypeがdatetime64になった

df_i.index

DatetimeIndex(['2022-08-19 00:30:00', '2022-08-19 00:45:00',
'2022-08-19 01:00:00', '2022-08-19 01:15:00',
'2022-08-19 01:30:00', '2022-08-19 01:45:00',
'2022-08-19 02:00:00', '2022-08-19 02:15:00',
'2022-08-19 02:30:00', '2022-08-19 02:45:00'],
dtype='datetime64[ns]', name='Date', freq=None)

インデックスを削除する

data4=data4.reset_index()

インデックスを付ける

data4=data4.set_index("Date", inplace=False)
# inplace=Trueは
data4.set_index("Date", inplace=True) ### data4をイコールで指定しなくても適応される

ipynbのファイルをtxtに変換する。で、特定語を含むファイルを検索する。

Jupyterlabのipynbファイルの内容を検索したい。その為にtxtだけのファイルに変換する。

入出力リダイレクトを使うので、新しくディレクトリを作り、そこに対象のipynbファイルをコピーする。
安全の為にそのディレクトリで操作を行う。

#!/usr/bin/bash

###
### ipynb to txt化
###

find ./ -name "*.ipynb" >list_ipynb

while read LINE
do
echo "$LINE"
LINE2=${LINE/ipynb/txt}

echo "$LINE2 に変換する"
jq -j '.cells | map( select(.cell_type == "code") | .source + ["\n\n"] ) | .[][]' < $LINE > $LINE2
done < list_ipynb
#!/usr/bin/bash

txt化したファイルができたら、検索語をxargs grepでファイルごとに検索する。

find ./ -name "*.txt" | xargs grep $1

BybitのSymbolsの取得

https://bybit-exchange.github.io/docs/futuresV2/inverse/#t-querysymbol


from pybit import inverse_perpetual
session_unauth = inverse_perpetual.HTTP(
endpoint="https://api-testnet.bybit.com"
)

r=session_unauth.query_symbol()
#len(r)
r
#len(r['result'])

pandas DataFrameを作成する。


import pandas as pd
df = pd.DataFrame(r['result'])

JypyterでPandas表示が切れるので全部表示するには

df = pd.DataFrame(r['result'])

pd.set_option('display.max_columns', None)
pd.set_option('display.max_rows', None)
pd.set_option('display.max_colwidth', None)

df

Fvwm3-1.0.5 来る

https://github.com/fvwmorg/fvwm3/releases/tag/1.0.5

https://github.com/fvwmorg/fvwm3

1年ぶりのアップデートがリリースされました。
いくつかの変更とバグフィックスがずらっとありますね。

Debianが先行し、Ubuntuにfvwm3が追加された具合である。
Ubuntu 22.10(kinetic)にパッケージ: fvwm3 (1.0.4+ds-1build1) [universe]
Debianはtestingとsidにパーケージが追加された。

bookworm (testing) (x11): F(?) Virtual Window Manager
1.0.5+ds-1: amd64 arm64 armel armhf i386 mips64el mipsel ppc64el s390x
sid (unstable) (x11): F(?) Virtual Window Manager
1.0.5+ds-1: alpha amd64 arm64 armel armhf hppa i386 m68k mips64el mipsel ppc64 ppc64el riscv64 s390x sh4 sparc64 x32

 

自分はUbuntu 22.04 LTS “Jammy Jellyfish”を使っている。パッケージはなく、いつものようにコンパイルしてインストールをする。

必要なパッケージはインストール

$sudo apt install libevent-dev libx11-dev libxrandr-dev libxrender-dev libxt-dev libxft-dev asciidoctor libfontconfig-dev libfreetype6-dev libfribidi-dev libncurses5-dev libpng-dev libreadline-dev librsvg2-dev libsm-dev libxcursor-dev libxext-dev libxi-dev libxpm-dev sharutils

gitからインストールを行う

$git clone https://github.com/fvwmorg/fvwm3.git

fvwm3ディレクトリーに移動し

$./autogen.sh
$./configure --enable-mandoc --enable-golang

Makefileの、’CPPFLAGS’を、CPPFLAGS = -march=nativeにして

$make clean && make -j10

sudoでインストールする

sudo make install

過去の記事

DestroyMenuStyle * Fvwm ってエラーになるんだな

DestroyMenuStyle * Fvwm   ##これエラーになる。
MenuStyle * Fvwm

ログを見るとエラーが出てる。

 CMD_DestroyMenuStyle: cannot destroy default menu style. To reset the default menu style use
  MenuStyle * fvwm, Foreground black, Background grey, Greyed slategrey, MenuColorset, ActiveColorset, GreyedColorset

MenuStyleをいじっていたので、どこでエラーがでるのかこのエラーメッセージだと分からないんだな。試してみて分かったのが、DestroyMenuStyle * Fvwmであった。そもそもDestroyMenuStyle * で エラーがでる。デフォルトのメニュースタイルは、Fvwm, Mwm, Winが用意されているが。これはDestroyMenuStyleできませんよ、ということですな。

Fvwm, Mwm, Win reset all options to the style with the same name in former versions of fvwm. The default for new menu styles is Fvwm style. These options
       override all others except Foreground, Background, Greyed, HilightBack, ActiveFore and PopupDelay, so they should be used only as the first option
       specified for a menu style or to reset the style to defined behavior. The same effect can be created by setting all the other options one by one.

       Mwm and Win style menus popup sub menus automatically. Win menus indicate the current menu item by changing the background to dark. Fvwm sub menus
       overlap the parent menu, Mwm and Win style menus never overlap the parent menu.

       Fvwm style is equivalent to !HilightBack, Hilight3DThin, !ActiveFore, !Animation, Font, MenuFace, PopupOffset 0 67, TitleWarp, TitleUnderlines1,
       SeparatorsShort, TrianglesRelief, PopupDelayed, PopdownDelayed, PopupDelay 150, PopdownDelay 150, PopupAsSubmenu, HoldSubmenus, SubmenusRight,
       BorderWidth 2, !AutomaticHotkeys, UniqueHotkeyActivatesImmediate, PopupActiveArea 75.

       Mwm style is equivalent to !HilightBack, Hilight3DThick, !ActiveFore, !Animation, Font, MenuFace, PopupOffset -3 100, !TitleWarp, TitleUnderlines2,
       SeparatorsLong, TrianglesRelief, PopupImmediately, PopdownDelayed, PopdownDelay 150, PopupAsSubmenu, HoldSubmenus, SubmenusRight, BorderWidth 2,
       UniqueHotkeyActivatesImmediate, !AutomaticHotkeys, PopupActiveArea 75.

       Win style is equivalent to HilightBack, Hilight3DOff, ActiveFore, !Animation, Font, MenuFace, PopupOffset -5 100, !TitleWarp, TitleUnderlines1,
       SeparatorsShort, TrianglesSolid, PopupImmediately, PopdownDelayed, PopdownDelay 150, PopupAsSubmenu, RemoveSubmenus, SubmenusRight, BorderWidth 2,
       UniqueHotkeyActivatesImmediate, !AutomaticHotkeys, PopupActiveArea 75.